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:

  1. The image from which I want to mask has a scale value 1. This image generally has a resolution greater than 1000x1000 pixels.
  2. 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添加蒙版的更多相关文章

  1. iOS给UIimage添加圆角的两种方式

    众所周知,给图片添加圆角有CALayer的cornerRadius, 比如: 最直接的方法: imgView.layer.cornerRadius1=110;   imgView.clipsToBou ...

  2. Android开发UI之给ImageView添加蒙版

    ImageView控件添加蒙版, 通过属性:android:tint="" 比如 android:tint="#44ff0000"

  3. UIImage添加滤镜

    UIImage *image =[UIImage imageNamed:"]; NSArray *arr = [NSArray arrayWithObjects:@"CISRGBT ...

  4. 使用cordova调用相机在相机中添加蒙版

    变态的需求,要在cordova调起得相机上加入一拍照的轮廓,在cordova的插件中拿不到拍照的方法,起初选用UIImagePickerController的cameraOverlayView属行,结 ...

  5. [UIImage resizableImageWithCapInsets:]

    [UIImage resizableImageWithCapInsets:]使用注意 转自:http://www.cnblogs.com/scorpiozj/p/3302270.html 最近在sae ...

  6. [UIImage resizableImageWithCapInsets:]使用注意

    转自:http://www.cnblogs.com/scorpiozj/p/3302270.html 最近在sae上搭建了个wp,因为深感自己前端的东西缺乏,所以想依次为契机,学习一下.本文是从个人的 ...

  7. Swift - 给图片添加滤镜效果(棕褐色老照片滤镜,黑白滤镜)

    Core Image是一个强大的滤镜处理框架.它除了可以直接给图片添加各种内置滤镜,还能精确地修改鲜艳程度, 色泽, 曝光等,下面通过两个样例演示如何给UIImage添加滤镜. 1,棕褐色滤镜  -  ...

  8. PS滤镜给城市夜空照片添加满天星

    原图 一.新建空白图层. 二.填充黑色(编辑→填充). 三.转换为智能对象. 四.添加杂色(滤镜→杂色→添加杂色). 五.使用高斯模糊(滤镜→模糊→高斯模糊). 六.如果你想再次修改模糊效果,可双击该 ...

  9. PS基础教程:[8]蒙版使用实例

    蒙版是PS中我们最常使用的工具,使用蒙版合成图片可以制作出非常绚丽的效果,并且看上去感觉很真,下面就以一个实例为大家分享一下蒙版的基本使用. 方法 1.在PS中打开准备好的素材,这里主要介绍蒙版的使用 ...

随机推荐

  1. C#_Socket网络编程实现的简单局域网内即时聊天,发送文件,抖动窗口。

    最近接触了C#Socket网络编程,试着做了试试(*^__^*) 实现多个客户端和服务端互相发送消息 发送文件抖动窗口功能 服务端: using System; using System.Collec ...

  2. OD: Big_Endian vs Little_Endian

    经调试,Windows 下为 Little_Endian,OD 中堆栈数据区的 (dword)0xAABB0102,0x02 存储在低地址,0x01 存储在高地址. 内容来自:http://blog. ...

  3. iOS 数据持久化

    一.plist文件存储 获得文件 NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDom ...

  4. javascript使用for循环批量注册的事件不能正确获取索引值的解决方法

    今天遇到一个问题,那就是当使用for循环批量注册事件处理函数,然后最后通过事件处理函数获取当前元素的索引值的时候会失败,先看一段代码实例: <script type="text/jav ...

  5. [置顶] chinayaosir近10年来所阅读的世界著名IT书籍-图文并茂

    1.人生观(包括做人原则,心理学,投资,销售) 一个人从来到世上,很多东西都是空白, 阅读一些正能量的书籍,把里面的理论用于生活,不断的应用它, 这些观念就会如同软件一样,不断的升级你的大脑, 合理的 ...

  6. FileOutputStream

    OutputStream: FileOutputStream BufferedOutputStream 缓冲输出流 package file; import java.io.File; import ...

  7. Android 网络通信框架Volley的简单使用

    Volley是Android平台上的网络通信库,能使网络通信更快,更简单,更健壮. Volley提供的功能: JSON,图像等的异步下载: 网络请求的排序(scheduling) 网络请求的优先级处理 ...

  8. LeetCode_Best Time to Buy and Sell Stock III

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  9. Keil中LIB库的作用、生成与调用

    LIB库有什么用,一个简单的例子就是Silicon Labs为C8051F单片机USB提供的USBXpress LIB库了,如USB发送数据.接收数据等,都是通用性很强的函数,但因为保密的原因,这个函 ...

  10. IDA pro 的Python环境变量设置

    推荐使用IDA PRO6.1+Python2.6 安装完毕Python2.6后,添加如下的环境变量: PYTHONHOME=C:\Python26PATH=%PATH%;C:\Python26LIB= ...