给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中打开准备好的素材,这里主要介绍蒙版的使用 ...
随机推荐
- 从客户端检测到危险的Request.Form值解决方案
1.修改aspx页面中的代码,设置ValidateRequest="false" <%@ Page Language="C#" AutoEventWire ...
- 华为oj 统计字符串不同字符
#include <stdio.h> #include <string.h> int firstSingle(char *str) { int hash[128]={0}; f ...
- 《Hadoop权威》学习笔记四:Hadoop的I/O
一.数据完整性 二.压缩 三.序列化 基本概念 序列化指的是将结构化对象转化为字节流以便于通过网络进行传输或写入持久化存储的过程 反序列化指的是将字节流转为一系列结构化对象的过程. 进程间通信 ...
- Content-Disposition的作用及用法
Content-disposition 是 MIME 协议的扩展,MIME 协议指示 MIME 用户代理如何显示附加的文件.Content-disposition其实可以控制用户请求所得的内容存为一个 ...
- Hibernate学习笔记--核心编程
参考资料:Java Web核心框架 http://blog.csdn.net/lsh6688/article/details/7611950 补充:ThreadLocal的使用:http://www. ...
- Swift 可选链-备
在Swift程序表达式中会看到问号(?)和感叹号(!),它们代表什么含义呢?这些符号都与可选类型和可选链相关,下面来看看可选链. 可选链: 类图: 它们之间是典型的关联关系类图.这些类一般都是实体类, ...
- PYTHON线程知识再研习B
使用threading.Thread模块,也有两种使用方法,可以用类,也可以在实例化对象中传入函数或类实例. #!/usr/bin/env python # -*- coding: utf-8 -*- ...
- Codeforces 437E The Child and Polygon
http://codeforces.com/problemset/problem/437/E 题意:求一个多边形划分成三角形的方案数 思路:区间dp,每次转移只从一个方向转移(L,R连线的某一侧),能 ...
- Altium Designer规则
1.PCB规则 是PCB设计中至关重要的一个环节:保证PCB符合电气要求.机械加工(精度)要求:为自动布局.布线和部分手动布局.布线操作提供依据 为规则检查提供依据,PCB编辑期间,AD会实时地进行一 ...
- logstash 处理tomcat access报ArgumentError: comparison of String with 5 failed
<pre name="code" class="html"> 10.168.102.19 - - [22/Sep/2016:20:35:11 +08 ...