我想将CIImage转换为UIImage但失败了

时间:2016-08-18 07:43:04

标签: ios objective-c uiimage ciimage cvpixelbuffer

我有一个格式为kCVPixelFormatType_420YpCbCr8BiPlanarFullRangeYCC420fN12)的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纹理的地址。

现在,我该怎么办?

1 个答案:

答案 0 :(得分:0)

只需一行简单的代码(可从IOS 5.0获得)

UIImage * uiImage = [[UIImage alloc] initWithCIImage:ciImage];