苹果开发 笔记(48) UIImage CIImage CGImageRef
2015-07-11 10:06
525 查看
UIImage 有很多有用的东西,前段时间接触了coreImage的API,发现有一个CIImage的东西,同样还有一个CGImage的东西,这三者总是可以切换起来,多少让人觉得这个东西很能耐。
IOS编程揭秘 书中记录着如下一段话。
UIImage类的Core Graphics
版本是CGImage(CGImageRef)这两个类之间很容易进行转换,因为一个UIImage类有一个CGImage的属性“
CGmage的创建过程
或者
CIImage的创建过程
UIImage—>CGImageRef
CGImageRef –> UIImage
最主要的一句
但是采用这种方式转换,CIImage的值会是nil,
相反 采用CIImage 的initWithCGImage初始化的方式 则有值,很奇怪
由此可见,三者都可以实现转换了,通过直接或者间接把他们联系起来。
UIImage –> CGImageRef –> CIImage
UIImage <– CGImageRef <– CIImage
IOS编程揭秘 书中记录着如下一段话。
UIImage类的Core Graphics
版本是CGImage(CGImageRef)这两个类之间很容易进行转换,因为一个UIImage类有一个CGImage的属性“
1.创建过程
UIImage 常规创建过程[code]UIImage *image =[ UIImage imageNamed:@"xx.png"];
CGmage的创建过程
[code]CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,CGRectMake(0,0,size.width,size.height));
或者
[code]UIImage *image =[ UIImage imageNamed:@"xx.png"]; CGImageRef imageRef = [image CGImage];
CIImage的创建过程
[code] NSString *path = [[NSBundle mainBundle] pathForResource:@"bbg" ofType:@"jpg"]; NSURL *myURL = [NSURL fileURLWithPath:path]; CIImage *ciImage = [CIImage imageWithContentsOfURL:myURL];
2.相互转换
UIImage, CGImageRef, CIImage 三者之间可以通过一些联系进行转换2.1 UIImage 转换CGImageRef
UIImage 类当中包含了CGImage的属性,所以很方便地就能转换,方法如下[code]UIImage *image =[ UIImage imageNamed:@"xx.png"]; CGImageRef imageRef = [image CGImage];
2.2 CGImageRef 转换UIImage
UIImage里面包含了一个方法imageWithCGImage,如果知道了CGImage,则这样子也可以创建得到UIIamge类,在上面我们可以看到关系 UIImage 通过属性得到CGImageRef,同样地两者也可以关联起来。UIImage—>CGImageRef
CGImageRef –> UIImage
[code]UIImage *uiImage =[UIImage imageWithCGImage:cgImage];
2.3 CIImage 转换CGImageRef
CIContext 当中有一个方法createCGImage,可以创建得到CGImageRef,换句话可知道CIImage 可以通过其他方式转换CGImageRef[code] CIContext *context = [CIContext contextWithOptions:nil]; CIImage *ciImage = [CIImage imageWithContentsOfURL:myURL]; filter = [filterWithName:@"CISepiaTone"]; [filter setValue:ciImage forKey:kCIInputImageKey]; [filter setValue:@0.8f forKey:kCIInputIntensityKey]; CIImage *outputImg = [filter outputImage]; CGImageRef cgImage = [context createCGImage:outputImg fromRect:[outputImg extent]];
最主要的一句
[code] CGImageRef cgImage = [context createCGImage:outputImg fromRect:[outputImg extent]];
2.4 UIImage 转换CIImage
[code]CIImage *ciImage = [UIImage imageNamed:@"test.png"].CIImage UIImage *image = [[UIImage alloc] initWithCIImage:ciImage];
但是采用这种方式转换,CIImage的值会是nil,
相反 采用CIImage 的initWithCGImage初始化的方式 则有值,很奇怪
[code] UIImage *image = [UIImage imageNamed:@"test.png"]; CIImage *ciImage = [[CIImage alloc]initWithCGImage:image.CGImage];
由此可见,三者都可以实现转换了,通过直接或者间接把他们联系起来。
UIImage –> CGImageRef –> CIImage
UIImage <– CGImageRef <– CIImage
相关文章推荐
- iOS中UILabel的用法(三 )
- LeetCode Implement Stack using Queues
- android程序中出现Type android:actionModeShareDrawable requires API level 21 (the min is 8)的解决方案
- Win7 64位系统搭建:UE4+CEGUI+VS2013游戏框架一
- UI基础:target...action设计模式,手势识别器.UIimageview
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW _TASK flag.
- c#利用WebClient和WebRequest获取网页源代码的比较
- java初级笔记_GUI
- [Android--UI]TextView的使用学习
- [Android--UI]界面设计原则
- [Android--UI]EditText的使用问题
- [Android--UI]ScrollView使用学习
- [Android--UI]颜色对照表
- continue用法
- [Vision]Vision Acquisition Software安装后IMAQdx,IMAQ函数不出现的问题
- EasyUI的progress对象close方法报错的彻底解决方案
- 【转】Windows和Ubuntu双系统,修复UEFI引导的两种办法
- iOS开发技巧(系列十八:扩展UIColor,支持十六进制颜色设置)
- LeetCode232:Implement Queue using Stacks
- UML建模之时序图(Sequence Diagram)