UIImage vs. CIImage vs. CGImage
yaofly2012 opened this issue · comments
yq commented
前缀:
- UI 表示来自
UIkit
- Core Image
- CoreGraphics
UIImage
, CIImage
, CGImage
UIImage
在APP里用于展示图片数据。CIImage
表示图片的数据,它包含创建图片的所有信息。CGImage
表示位图
CIImage
CGImage
互转
CIImage
转CGImage
#import <CoreImage/CoreImage.h>
CIImage *ciImage = [CIImage imageWithData:data];
CIContext *ciContext = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [ciContext createCGImage:ciImage fromRect:[ciImage extent]];
CGImage
转CIImage
CIImage
提供了专门的API:
initWithCGImage
CIImage
/CGImage
转UIImage
UIImage
是顶层API,本身自带了将CIImage
, CGImage
转UIImage
API:
initWithCGImage:(CGImageRef)cgImage
initWithCIImage:(CIImage *)ciImage
UIImage
转CGImage
先把UIImage
转``CIImage,再转CGImage
。