我有一个格式为kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
(YCC420f
或N12
)的CIImage,现在我想查看图片的样子,所以我将它转换为UIImage使用此方法:< / p>
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:new_buffer];
CIContext *temporaryContext = [CIContext contextWithOptions:nil];
CGImageRef videoImage = [temporaryContext
createCGImage:ciImage
fromRect:CGRectMake(0, 0,
CVPixelBufferGetWidth(new_buffer),
CVPixelBufferGetHeight(new_buffer))];
UIImage *uiImage = [UIImage imageWithCGImage:videoImage];
当图像的格式为BGRA
时,它可以正常工作,而NV12
则没有,在控制台中出现错误信息:
Render failed because a pixel format YCC420f is not supported.
顺便说一句,ciimage来自CVPixelBufferRef,而CVPixelBufferRef来自GL纹理的地址。
现在,我该怎么办?
答案 0 :(得分:0)
只需一行简单的代码(可从IOS 5.0获得)
UIImage * uiImage = [[UIImage alloc] initWithCIImage:ciImage];