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. Tree( 树) 组件[3]

    本节课重点了解 EasyUI 中 Tree(树)组件的使用方法, 这个组件依赖于 Draggable(拖动)和 Droppable(放置)组件.一. 事件列表很多事件的回调函数都包含'node'参数, ...

  2. ASP.NET快速学习方案(.NET菜鸟的成长之路)

    想要快速学习ASP.NET网站开发的朋友可以按照下面这个学习安排进度走.可以让你快速入门asp.net网站开发!但也局限于一般的文章类网站!如果想学习更多的技术可以跟着我的博客更新走!我也是一名.NE ...

  3. 基于live555的一个简单RTSP服务器

    1,编译live555源码目录下的 BasicUsageEnvironment.groupsock.liveMedia.UsageEnvironment四个工程生成相应的库文件: 目录结构如下: 2, ...

  4. Chrome调试nodejs

    1.安装node-inspector 命令: npm install -g node-inspector 2.nodemon --debug xxx.js启动项目(如果使用--debug-brk 就会 ...

  5. C#编码标准--编码习惯

    C#编码标准--编码习惯 0.  书写程序时的大小写规则: a) 类:PascalCase表示法.如 MyClass b) 枚举值:PascalCase表示法.如 Colors.Red c) 枚举类型 ...

  6. php之类,对象(四)加载类及练习题

    一.加载类:1.命名类文件的时候每个单词首字母大写,后面缀上.class.php eg: Info.class.php 在写编码时定义类名首字母大写,定义变量名小写 eg:class Ren { pu ...

  7. twemproxy 安装

    twemproxy 安装 1. 获取安装包 shell> wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz shell> ...

  8. ubuntu -server 忘记root 密码方法

    允许 su 到 root 非常简单,只需要重新设置下密码即可.下面是设置的方法: 1 me@ubuntu:~$ sudo passwd 2 密码:<--- 输入安装时那个用户的密码3 输入新的 ...

  9. Flask Jinjia2 与 react

    Jinjia2 这是flask使用的模板工具,利用render_template方法可以方便的将后端的数据传给前端. 但是如果要使用react呢. 我如果在jsx中直接使用{{}}是不能输出变量的. ...

  10. jave script 经典排序 - -冒泡排序

    有 5个数字,2:3:1:0:4,按大小顺序排列 <script type="text/javascript"> var arr =new Array(); arr . ...