强大的Core Image框架,各种滤镜处理图像
首先介绍一下Core Image,他是一个很强大的图像处理框架,他可以让你简单的应用各种滤镜来处理图像,比如说色相,饱和度,亮度等等。。。他是运用GPU(CPU)实时地处理图像数据和视频的帧。而且Core Image滤镜可以叠加在一起,产生多滤镜的效果。因为没有滤镜都有属于自己唯一的参数,可以通过修改这些参数来达到预期效果。
在应用Core Image时,要注意着三个比较总要的类:CIContext ,CIImage ,CIFilter.
1.CIContext:所有的图像处理都在一个CIContext中完成,相当于OpenGL中的上下文;
2.CIImage:用来保存图像数据。同时他可以通过像素数据构造出来;
//创建CIImage对象
UIImage *image = [UIImage imageNamed:@"test.png"];
NSData *data = UIImagePNGRepresentation(image);
self.ciImage = [CIImage imageWithData:data];
3.CIFiter:包含了一个字典结构的滤镜类,同时滤镜有很多中。各种滤镜都定义了他们独自不同的属性。他的种类有很多,可以参考http://blog.sina.com.cn/s/blog_5fb39f9101018g34.html
//打印所有的滤镜类型
NSArray *cifilter = [CIFilter filterNamesInCategory:kCICategoryBuiltIn];
NSLog(@"滤镜名称:\n%@\n滤镜数:%ld", cifilter,cifilter.count);
废话不多说,直接上代码
//创建CIImage对象
UIImage *image = [UIImage imageNamed:@"girl.png"];
NSData *data = UIImagePNGRepresentation(image);
self.ciImage = [CIImage imageWithData:data];
// 创建基于CPU的CIContext对象
self.context = [CIContext contextWithOptions:nil];
// 创建过滤器
//调节色相
self.colourFilter = [CIFilter filterWithName:@"CIHueAdjust"];
[self.colourFilter setDefaults];
// 设置过滤器参数,来改变图像数据
在设置过滤器的参数时,你要明确当前过滤器的属性,可以通过打印出相应过滤器的字典数据查看并进一步更改:
NSLog(@"CIHueAdjust______%@",[self.colourFilter attributes]);
/**
inputAngle = {
CIAttributeClass = NSNumber;
CIAttributeDefault = 0;
CIAttributeDescription = "An angle (in radians) to use to correct the hue of an image.";
CIAttributeDisplayName = Angle;
CIAttributeIdentity = 0;
CIAttributeSliderMax = "3.141592653589793";
CIAttributeSliderMin = "-3.141592653589793";
CIAttributeType = CIAttributeTypeAngle;
};
inputImage = {
CIAttributeClass = CIImage;
CIAttributeDescription = "The image to use as an input image. For filters that also use a background image, this is the foreground image.";
CIAttributeDisplayName = Image;
CIAttributeType = CIAttributeTypeImage;
};
*/
//可以看到inputAngle输入角度的取值范围"-3.141592653589793-3.141592653589793"
[_colourFilter setValue:_ciImage forKey:@"inputImage"];
[_colourFilter setValue:[NSNumber numberWithFloat:2] forKey:@"inputAngle"];
// 得到过滤后的图片
CIImage *outputImage = [_colourFilter outputImage];
// 转换图片
CGImageRef cgimg = [_context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];
// 显示图片
[_imageView setImage:newImg];
CGImageRelease(cgimg);
具体demo链接https://github.com/White007/CIFilterDemo.git
强大的Core Image框架,各种滤镜处理图像的更多相关文章
- Core Graphics框架
在iOS中常用的框架是Quartz 2D,它是Core Graphics框架的一部分,是一个强大的二维图像绘制引擎.我们日常开发所用到的UIKit的组件都是由Core Graphics框架进行绘制的. ...
- iOS绘图UIBezierPath 和 Core Graphics框架
前言 iOS系统本身提供了两套绘图的框架,即UIBezierPath 和 Core Graphics.而前者所属UIKit,其实是对Core Graphics框架关于path的进一步封装,所以使用起来 ...
- 强大的Core Image(教你做自己的美图秀秀))
iOS5新特性:强大的Core Image(教你做自己的美图秀秀)) iOS5给我们带来了很多很好很强大的功能和API.Core Image就是其中之一,它使我们很容易就能处理图片的各种效 ...
- ASP.NET Core 6框架揭秘实例演示[01]: 编程初体验
作为<ASP.NET Core 3框架揭秘>的升级版,<ASP.NET Core 6框架揭秘>提供了很多新的章节,同时对现有的内容进行大量的修改.虽然本书旨在对ASP.NET ...
- ASP.NET Core 6框架揭秘实例演示[19]:数据加解密与哈希
数据保护(Data Protection)框架旨在解决数据在传输与持久化存储过程中的一致性(Integrity)和机密性(confidentiality)问题,前者用于检验接收到的数据是否经过篡改,后 ...
- Core Foundation框架
转载自:http://blog.csdn.net/weiwangchao_/article/details/7744972 Core Foundation框架 (CoreFoundation.fram ...
- IOS之Core Foundation框架和Cocoa Foundation框架的区别
Core Foundation框架 (CoreFoundation.framework) 是一组C语言接口,它们为iOS应用程序提供基本数据管理和服务功能.下面列举该框架支持进行管理的数据以及可提供的 ...
- iPhone的定位技术与Core Location框架
来源:http://www.cnblogs.com/lovecode/archive/2011/12/24/2300579.html iPhone定位来源通常有:1. GPS定位 2. WiFi定位 ...
- 【转】Core Bluetooth框架之一:Central与Peripheral
原文网址:http://southpeak.github.io/blog/2014/07/29/core-bluetoothkuang-jia-zhi-%5B%3F%5D-:centralyu-per ...
随机推荐
- Android 每天定时提醒功能实现
android要实现定时的功能那肯定就要用到闹铃相关的技术, 那么android闹铃实现是基于 AlarmManager 这个类的,首先我们来看一下它的几个主要的方法. 打开AlarmManager的 ...
- 在代码中创建Drawable资源
如何在代码中创建圆环: 先看效果图 代码; import android.graphics.drawable.GradientDrawable; GradientDrawable circle = n ...
- 【转】ButterKnife基本使用--不错
原文网址:http://www.cnblogs.com/mengdd/archive/2015/06/23/4595973.html Butter Knife处理字段和方法绑定. 配置: 用gradl ...
- smtp服务器搭建(实现本地通讯)
1安装postfix 1)下载安装包 sudo apt-get install postfix 2)配置服务器 选择确定. 选择IneternetSite(通过SMTP发送和接收邮件),然后确定 ...
- UVA 11021 Tribles(递推+概率)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 [思路] 递推+概率. 设f[i]表示一只Tribble经 ...
- 排序Tip
排序算法 所有排序算法汇总:http://en.wikipedia.org/wiki/Sort_algorithm counting sort 资料 :http://www.cs.miami.ed ...
- MySQL高可用性大杀器之MHA | 火丁笔记
MySQL高可用性大杀器之MHA | 火丁笔记 MySQL高可用性大杀器之MHA
- Google Picasa
本博文的主要内容有 .Google Picasa的下载 .Google Picasa的安装 .Google Picasa的使用 Google 的免费图片管理工具Picasa,数秒钟内就可找到并欣赏计算 ...
- zoj 1671 Walking Ant【简单bfs】
Walking Ant Time Limit: 2 Seconds Memory Limit: 65536 KB Ants are quite diligent. They sometime ...
- iOS获取经纬度
在ios8.0以上获取经纬度时,需要申请授权,否则不能定位 第一步: 在 HomeViewController.m @interfaceHomeViewController ()<CLLoc ...