【iOS入门】UIImage及相关类

iOS image
UIImage
创建过程
UIImage 常规创建过程
UIImage *image =[ UIImage imageNamed:@"xx.png"];

CGmage的创建过程
CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,CGRectMake(0,0,size.width,size.height));
或者
UIImage *image =[ UIImage imageNamed:@"xx.png"];
CGImageRef imageRef = [image CGImage];

CGImage
CGmage的创建过程
CGImageRef imageRef =CGImageCreateWithImageInRect(image.CGImage,CGRectMake(0,0,size.width,size.height));

或者

UIImage *image =[ UIImage imageNamed:@"xx.png"];
CGImageRef imageRef = [image CGImage];

CIImage
创建
NSString *path = [[NSBundle mainBundle] pathForResource:@"bbg" ofType:@"jpg"];
NSURL *myURL = [NSURL fileURLWithPath:path];

CIImage *ciImage = [CIImage imageWithContentsOfURL:myURL];


三者区别
CIImage 包含了创建图片的所有必要的数据,但其本身没有渲染成图片,它代表的是图像数据或者生成图像数据的流程(如滤镜);
CGImage是基于像素的矩阵,每个点都对应了图片中点的像素信息;
UIImage 管理图片数据,主要用来展现,如 UIImageView 中,控件中等,也可以用来直接在 view 或其他的 context 中绘制。
CIImage包含图片的所有必要数据,如作者信息,图片类型,拍摄地点,图片大小等等信息。
UIImage也会包含一些图片的必要数据,如图片大小,图片宽高。但在CIImage转UIImage的时候,会丢失一部分信息,如作者信息等非必要数据。

猜你喜欢

转载自www.cnblogs.com/mamamia/p/12171053.html