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 处理图片的更多相关文章

  1. [Swift通天遁地]四、网络和线程-(10)处理图片:压缩、缩放、圆角、CoreImage滤镜、缓存

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. IOS 中的CoreImage框架(framework)

    http://www.cnblogs.com/try2do-neo/p/3601546.html coreimage framework 组成 apple 已经帮我们把image的处理分类好,来看看它 ...

  3. IOS 中的CoreImage框架

    IOS 中的CoreImage框架(framework) - time4cnblogs 时间 2014-03-15 00:24:00  博客园-所有随笔区原文  http://www.cnblogs. ...

  4. 基于iOS用CoreImage实现人脸识别

    2018-09-04更新: 很久没有更新文章了,工作之余花时间看了之前写的这篇文章并运行了之前写的配套Demo,通过打印人脸特征CIFaceFeature的属性,发现识别的效果并不是很好,具体说明见文 ...

  5. 使用CoreImage教程

    使用CoreImage教程 CoreImage包含有很多实用的滤镜,专业处理图片的库,为了能看到各种渲染效果,请使用如下图片素材. 现在可以开始教程了: #define FIX_IMAGE(image ...

  6. 11 (OC)* CoreImage

    coreimage framework 组成 apple 已经帮我们把image的处理分类好,来看看它的结构: 主要分为三部分: 1)定义部分:CoreImage 何CoreImageDefines. ...

  7. nodejs处理图片、CSS、JS链接

    接触Nodejs不深,看到页面上每一个链接都要写一个handler,像在页面显示图片,或者调用外部CSS.JS文件,每个链接都要写一个handler,觉得太麻烦,是否可以写个程序出来,能够自动识别图片 ...

  8. PHPThumb处理图片,生成缩略图,图片尺寸调整,图片截取,图片加水印,图片旋转

    [强烈推荐]下载地址(github.com/masterexploder/PHPThumb). 注意这个类库有一个重名的叫phpThumb,只是大小写的差别,所以查找文档的时候千万注意. 在网站建设过 ...

  9. Filter Effects - 使用 CSS3 滤镜处理图片

    CSS3 Filter(滤镜)属性提供了提供模糊和改变元素颜色的功能.CSS3 Fitler 常用于调整图像的渲染.背景或边框显示效果.这里给大家分享的这个网站,大家可以体验下 CSS3 对图片的处理 ...

随机推荐

  1. c#winform如何通过控件名查找控件

    //根据控件名称查找控件 //作用根据控件的配置项目, Control[] myfindcs = this.Controls.Find("button4", true); if ( ...

  2. Postman-简单使用

    Postman-简单使用 Postman-进阶使用 Postman-CI集成Jenkins Postman功能(https://www.getpostman.com/features) 主要用于模拟网 ...

  3. Python3学习(2)-中级篇

    Python3学习(1)-基础篇 Python3学习(2)-中级篇 Python3学习(3)-高级篇 切片:取数组.元组中的部分元素 L=['Jack','Mick','Leon','Jane','A ...

  4. iOS中数字的格式化 NSNumberFormatter

    NSNumberFormatter 和NSDateFormatter 是NsFormatter的子类. NSNumberFormatter类有个属性numberStyle,它是一个枚举型,设置不同的值 ...

  5. 如何处理webView跳转

    - (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {    // Give iOS a chance to o ...

  6. Magicodes.WeiChat——缓存管理

    本框架支持缓存管理,内部机制使用开源库CacheManager.支持全局缓存.租户缓存,默认使用的系统缓存实现,可以在Web.config将其配置为其他缓存类型,比如支持Redis.内存等. 开源库地 ...

  7. 初学者利用git 上传代码到Coding的简单操作步骤

    1.首先登陆coding网站注册账号https://coding.net/ (注册完后需登陆邮箱激活邮件) 2.登陆刚注册的coding账号 ,添加项目 添加项目—〉输入项目名称—〉输入对项目的简单描 ...

  8. Server Develop (八) IOCP模型

    IOCP模型 IOCP全称I/O Completion Port,中文译为I/O完成端口.IOCP是一个异步I/O的Windows API,它可以高效地将I/O事件通知给应用程序,类似于Linux中的 ...

  9. [ucgui] 对话框2——小窗口初始化与消息响应

    >_<" 上一节已经说过,创建过得窗口虽然可见,但是它们是以 “空”的形式出现的.这是因为对话框过程函数尚未包含初始化单个元素的代码.小工具的初始值.由它们所引起的行为以及它们之 ...

  10. jQuery的XX如何实现?——1.框架

    源码链接:内附实例代码 jQuery使用许久了,但是有一些API的实现实在想不通.于是抽空看了jQuery源码,现在把学习过程中发现的一些彩蛋介绍给大家(⊙0⊙). 下面将使用简化的代码来介绍,主要关 ...