CoreImage 处理图片
1.CoreImage
滤镜的使用(马赛克模糊)
CoreImage是苹果公司为了简化图片处理的难度而开发出来的类库。
随着iOS版本号升级以及硬件性能的不断提升,CoreImage将支持越来越多的滤镜
- (void)hFilter {
// 0.
导入CIImage图片
CIImage *ciImage = [[CIImagealloc] initWithImage:[UIImageimageNamed:@"demo"]];
// 1.
创建出Filter滤镜
CIFilter *filter = [CIFilterfilterWithName:@"CIPixellate"];
[filtersetValue:ciImage
forKey:kCIInputImageKey];
NSLog(@"%@", filter.attributes);
[filtersetDefaults];
CIImage *outImage = [filter valueForKey:kCIOutputImageKey];
// 2.
用CIContext将滤镜中的图片渲染出来
CIContext *context = [CIContextcontextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:outImage
fromRect:[outImage extent]];
// 3.
导出图片
UIImage *showImage = [UIImageimageWithCGImage:cgImage];
CGImageRelease(cgImage);
// 4.
载入出来
UIImageView *imageView = [[UIImageViewalloc] initWithImage:showImage];
imageView.center =self.view.center;
[self.viewaddSubview:imageView];
}
2.CoreImage
滤镜的组合
不同的滤镜能够组合在一起使用。
能够动态的改动滤镜组合中单个滤镜的參数来实现一种动态调整的效果
- (void)complexCoreImage {
// 0.
导入CIImage图片
CIImage *ciImage = [[CIImagealloc] initWithImage:[UIImageimageNamed:@"demo"]];
// 1.
创建出Filter滤镜
CIFilter *filterOne = [CIFilterfilterWithName:@"CIPixellate"];
[filterOnesetValue:ciImage
forKey:kCIInputImageKey];
[filterOnesetDefaults];
CIImage *outImage = [filterOne valueForKey:kCIOutputImageKey];
CIFilter *filterTwo = [CIFilterfilterWithName:@"CIHueAdjust"];
[filterTwosetValue:outImage
forKey:kCIInputImageKey];
[filterTwosetDefaults];
//默觉得0,不设置不能改变。能够封装一个调用
[filterTwosetValue:@(3.14)
forKey:kCIInputAngleKey];
NSLog(@"%@",filterTwo.attributes);//能够看到一些參数 key
CIImage *outputImage = [filterTwo valueForKey:kCIOutputImageKey];
// 2.
用CIContext将滤镜中的图片渲染出来
CIContext *context = [CIContextcontextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:outputImage
fromRect:[outImage extent]];
// 3.
导出图片
UIImage *showImage = [UIImageimageWithCGImage:cgImage];
CGImageRelease(cgImage);
// 4.
载入出来
UIImageView *imageView = [[UIImageViewalloc] initWithImage:showImage];
imageView.center =self.view.center;
[self.viewaddSubview:imageView];
}
3.在 OpenGLES
下进行渲染
在OpenGLES下进行滤镜的渲染能够提高效率。(GPU渲染,不占用CPU)
假设须要实时查看多个滤镜动态渲染的效果,使用OpenGLES是一个好的选择
#import <GLKit/GLKit.h>
@interface
ViewController ()
@property (nonatomic,strong)
GLKView *glkView;// 渲染用的buffer视图
@property (nonatomic,strong)
CIFilter *filter;
@property (nonatomic,strong)
CIImage *ciImage;
@property (nonatomic,strong)
CIContext *ciContext;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
UIImage *showImage = [UIImageimageNamed:@"demo"];
CGRect rect =
CGRectMake(, , showImage.size.width, showImage.size.height);
//
获取OpenGLES渲染的上下文
EAGLContext *eagContext = [[EAGLContextalloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
//
创建出渲染的buffer
_glkView = [[GLKViewalloc] initWithFrame:rect
context:eagContext];
[_glkViewbindDrawable];
[self.viewaddSubview:_glkView];
//
创建出CoreImage用的上下文
_ciContext = [CIContextcontextWithEAGLContext:eagContext
options:@{kCIContextWorkingColorSpace : [NSNullnull]}];
// CoreImage相关设置
_ciImage = [[CIImagealloc] initWithImage:showImage];
_filter = [CIFilterfilterWithName:@"CISepiaTone"];
[_filtersetValue:_ciImageforKey:kCIInputImageKey];
[_filtersetValue:@(0)forKey:kCIInputIntensityKey];
//
開始渲染
[_ciContextdrawImage:[_filteroutputImage]
inRect:CGRectMake(,, _glkView.drawableWidth,_glkView.drawableHeight)
fromRect:[_ciImageextent]];
[_glkViewdisplay];
//
动态渲染
,,
, )];
slider.minimumValue =0.f;
slider.maximumValue =1.f;
[slider addTarget:selfaction:@selector(sliderEvent:)forControlEvents:UIControlEventValueChanged];
[self.viewaddSubview:slider];
}
- (void)sliderEvent:(UISlider *)slider {
[_filtersetValue:_ciImageforKey:kCIInputImageKey];
[_filtersetValue:@(slider.value)
forKey:kCIInputIntensityKey];
//
開始渲染
[_ciContextdrawImage:[_filteroutputImage]
inRect:CGRectMake(,, _glkView.drawableWidth,_glkView.drawableHeight)
fromRect:[_ciImageextent]];
[_glkViewdisplay];
}
CoreImage 处理图片的更多相关文章
- [Swift通天遁地]四、网络和线程-(10)处理图片:压缩、缩放、圆角、CoreImage滤镜、缓存
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- IOS 中的CoreImage框架(framework)
http://www.cnblogs.com/try2do-neo/p/3601546.html coreimage framework 组成 apple 已经帮我们把image的处理分类好,来看看它 ...
- IOS 中的CoreImage框架
IOS 中的CoreImage框架(framework) - time4cnblogs 时间 2014-03-15 00:24:00 博客园-所有随笔区原文 http://www.cnblogs. ...
- 基于iOS用CoreImage实现人脸识别
2018-09-04更新: 很久没有更新文章了,工作之余花时间看了之前写的这篇文章并运行了之前写的配套Demo,通过打印人脸特征CIFaceFeature的属性,发现识别的效果并不是很好,具体说明见文 ...
- 使用CoreImage教程
使用CoreImage教程 CoreImage包含有很多实用的滤镜,专业处理图片的库,为了能看到各种渲染效果,请使用如下图片素材. 现在可以开始教程了: #define FIX_IMAGE(image ...
- 11 (OC)* CoreImage
coreimage framework 组成 apple 已经帮我们把image的处理分类好,来看看它的结构: 主要分为三部分: 1)定义部分:CoreImage 何CoreImageDefines. ...
- nodejs处理图片、CSS、JS链接
接触Nodejs不深,看到页面上每一个链接都要写一个handler,像在页面显示图片,或者调用外部CSS.JS文件,每个链接都要写一个handler,觉得太麻烦,是否可以写个程序出来,能够自动识别图片 ...
- PHPThumb处理图片,生成缩略图,图片尺寸调整,图片截取,图片加水印,图片旋转
[强烈推荐]下载地址(github.com/masterexploder/PHPThumb). 注意这个类库有一个重名的叫phpThumb,只是大小写的差别,所以查找文档的时候千万注意. 在网站建设过 ...
- Filter Effects - 使用 CSS3 滤镜处理图片
CSS3 Filter(滤镜)属性提供了提供模糊和改变元素颜色的功能.CSS3 Fitler 常用于调整图像的渲染.背景或边框显示效果.这里给大家分享的这个网站,大家可以体验下 CSS3 对图片的处理 ...
随机推荐
- UIView的剖析(转)
转自:http://blog.csdn.net/mengtnt/article/details/6716289 前面说过UIViewController,但是UIView也是在MVC中非常重要的一层 ...
- Maven + 最新SSM整合
. 1. 开发环境搭建 参考博文:Eclipse4.6(Neon) + Tomcat8 + MAVEN3.3.9 + SVN项目完整环境搭建 2. Maven Web项目创建 2.1. 2.2. 2. ...
- 如何使不同主机上的docker容器互相通信
docker启动时,会在宿主主机上创建一个名为docker0的虚拟网络接口,默认选择172.17.42.1/16,一个16位的子网掩码给容器提供了65534个IP地址.docker0只是一个在绑定到这 ...
- WP8:在Cocos2d-x中使用OpenXLive
一. Cocos2d-x for Windows Phone 到2013年底,几大手游引擎都陆续支持WP8了,特别是Unity3D和Cocos2d-x.有过游戏开发经验的朋友们应该对这两个引擎不 ...
- 动手写一个Remoting接口测试工具(附源码下载)
基于.NET开发分布式系统,经常用到Remoting技术.在测试驱动开发流行的今天,如果针对分布式系统中的每个Remoting接口的每个方法都要写详细的测试脚本,无疑非常浪费时间.所以,我想写一个能自 ...
- Nginx运行Mono Web (ASP.NET)
Mono Web除了可以使用Apache/mod_mono方式承载运行外,还可以使用Nginx/FastCGI方式运行. Nginx配置asp.net更简单方便,用处也多,可以通过FastCGI运行a ...
- android 用NineOldAndroid实现的弹出按钮
NineOldAndroid 1.首先上效果图: 左边这张是没有点击button的时候的效果, 右边这张是点击button 后是以该button为圆的展开5个button
- 带你看懂Dictionary的内部实现
了解Dictionary的开发人员都了解,和List相比,字典添加会慢,但是查找会比较快,那么Dictionary是如何实现的呢? Dictionary的构造 下面的代码我看看Dictionary在构 ...
- WPF oxyPlot 使用总结
oxyPlot能够简易的创建图表并且该库也在Github上面开源直通门.以下是笔者基础使用总结.本文例子的源码下载 1.安装与引用 新建一个wpf应用程序,然后使用Nuget控制台安装OxyPlot和 ...
- ViEmuVS2013-3.2.1 破解
VS升级到2013后,作为一个Vimer,自然需要更新最新的ViEmu插件,因为现在离了Vim,写代码已经寸步难行了. ViEmu 3.2.1的破解其实和Viemu 3.0.13的破解方法一样.安装前 ...