给UIImage添加蒙版
http://stackoverflow.com/questions/17448102/ios-masking-an-image-keeping-retina-scale-factor-in-account
I want to mask an image by passing another image as mask. I am able to mask the image but the resulting image doesn't look good. It is jagged at borders.
I guess the problem is related to retina graphics. The scale property for the two images are different as:
- The image from which I want to mask has a scale value 1. This image generally has a resolution greater than 1000x1000 pixels.
- The image according to which I want the resulting image(image having black and white colors only) has scale value 2. This image is generally of resolution 300x300 pixels.
The resulting image has a scale value of 1.
The code I am using is:
+ (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
CGImageRef maskRef = maskImage.CGImage;
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
CGImageRelease(mask);
UIImage *maskedImage = [UIImage imageWithCGImage:masked ];
CGImageRelease(masked);
return maskedImage;
}
How can I get a masked image which follows retina scale?
给UIImage添加蒙版的更多相关文章
- iOS给UIimage添加圆角的两种方式
众所周知,给图片添加圆角有CALayer的cornerRadius, 比如: 最直接的方法: imgView.layer.cornerRadius1=110; imgView.clipsToBou ...
- Android开发UI之给ImageView添加蒙版
ImageView控件添加蒙版, 通过属性:android:tint="" 比如 android:tint="#44ff0000"
- UIImage添加滤镜
UIImage *image =[UIImage imageNamed:"]; NSArray *arr = [NSArray arrayWithObjects:@"CISRGBT ...
- 使用cordova调用相机在相机中添加蒙版
变态的需求,要在cordova调起得相机上加入一拍照的轮廓,在cordova的插件中拿不到拍照的方法,起初选用UIImagePickerController的cameraOverlayView属行,结 ...
- [UIImage resizableImageWithCapInsets:]
[UIImage resizableImageWithCapInsets:]使用注意 转自:http://www.cnblogs.com/scorpiozj/p/3302270.html 最近在sae ...
- [UIImage resizableImageWithCapInsets:]使用注意
转自:http://www.cnblogs.com/scorpiozj/p/3302270.html 最近在sae上搭建了个wp,因为深感自己前端的东西缺乏,所以想依次为契机,学习一下.本文是从个人的 ...
- Swift - 给图片添加滤镜效果(棕褐色老照片滤镜,黑白滤镜)
Core Image是一个强大的滤镜处理框架.它除了可以直接给图片添加各种内置滤镜,还能精确地修改鲜艳程度, 色泽, 曝光等,下面通过两个样例演示如何给UIImage添加滤镜. 1,棕褐色滤镜 - ...
- PS滤镜给城市夜空照片添加满天星
原图 一.新建空白图层. 二.填充黑色(编辑→填充). 三.转换为智能对象. 四.添加杂色(滤镜→杂色→添加杂色). 五.使用高斯模糊(滤镜→模糊→高斯模糊). 六.如果你想再次修改模糊效果,可双击该 ...
- PS基础教程:[8]蒙版使用实例
蒙版是PS中我们最常使用的工具,使用蒙版合成图片可以制作出非常绚丽的效果,并且看上去感觉很真,下面就以一个实例为大家分享一下蒙版的基本使用. 方法 1.在PS中打开准备好的素材,这里主要介绍蒙版的使用 ...
随机推荐
- django: form fileupload - 2
继续介绍文件上传的第二种形式和第三种形式. ------------------------------------------------------------- 第二种形式较简单,直接用 DB ...
- Android(通用机能)
数据存储 本地数据存在都是私有化的. 共享方法1是构造数据源组件.方法2将数据放入扩展存储设备. Mashup 服务组件默认没有运行在独立进程或线程中,因此费时操作一般需要起线程.可配置指定新进程. ...
- JSON.parse(),JSON.stringify(),jQuery.parseJSON()的用法
1. JSON.parse(jsonString): 在一个字符串中解析出JSON对象 var str = '[{"href":"baidu.com",&quo ...
- struct可以拥有class般的构造函数
struct A { int a, b; A(int x, int y) :a(x), b(y){} }; int main() { A a(1, 2); cout << a.a < ...
- 面试题,自己写写dome总是好的
1.完成如下图所示的布局 <html> <head> <meta http-equiv="Content-Type" content="te ...
- php文件格式数组
一个文件格式对应的数组$mime_types = array('gif' => 'image/gif','jpg' => 'image/jpeg','jpeg' => 'image/ ...
- PclZip:强大的PHP压缩与解压缩zip类
PclZip简介PclZip是一个很强大的压缩与解压缩zip文件的PHP类,PclZip library能够压缩与解压缩Zip格式的压缩档(WinZip.PKZIP):且能对此类类档案进行处理,包括产 ...
- JavaScript进阶学习的一些建议
blankyao最近问我如何学习JavaScript,他觉着在理解了JavaScript的语法之后,不知如何去学习JavaScript了. 其实我也是个JavaScript小菜,最近在开发中遇到不少关 ...
- jQuery读取JSON总结
1.jQuery 部分 <script src="js/jquery.js" type="text/javascript"></script& ...
- pubwin数据云备份
由于pubwin自带的异地备份一直不好用,并且pubwin自带的37分钟备份也不方便手动备份,考虑用python 与写一个基于酷盘的pubwin数据备份工具(本来想基于百度云的,发现百度云用的人太多, ...