我想将YUV图像转换为CIIMage并最终转换成UIImage。我在这些方面相当新手,并试图找出一个简单的方法来做到这一点。从我所学到的,从iOS6 YUV可以直接用来创建CIImage,但正如我试图创建它,CIImage只保留一个零值。我的代码是这样的 - >如何转换YUV至CIImage for iOS
NSLog(@"Started DrawVideoFrame\n");
CVPixelBufferRef pixelBuffer = NULL;
CVReturn ret = CVPixelBufferCreateWithBytes(
kCFAllocatorDefault, iWidth, iHeight, kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
lpData, bytesPerRow, 0, 0, 0, &pixelBuffer
);
if(ret != kCVReturnSuccess)
{
NSLog(@"CVPixelBufferRelease Failed");
CVPixelBufferRelease(pixelBuffer);
}
NSDictionary *opt = @{ (id)kCVPixelBufferPixelFormatTypeKey :
@(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) };
CIImage *cimage = [CIImage imageWithCVPixelBuffer:pixelBuffer options:opt];
NSLog(@"CURRENT CIImage -> %p\n", cimage);
UIImage *image = [UIImage imageWithCIImage:cimage scale:1.0 orientation:UIImageOrientationUp];
NSLog(@"CURRENT UIImage -> %p\n", image);
这里的lpData是YUV数据,它是一个无符号字符数组。
这也看起来很有趣:vImageMatrixMultiply,找不到任何这方面的例子。谁能帮我这个?
[This](https://developer.apple.com/library/ios/documentation/graphicsimaging/Conceptual/CoreImaging/ci_performance/ci_performance.html)可能对您有所帮助。 – swiftBoy 2014-09-04 07:34:57
谢谢,我已经检查过这个链接了。我正在关注这一点,并使用这样的选项,但CIImage没有被初始化 – d1xlord 2014-09-04 08:16:40
我发现这个[链接](http://stackoverflow.com/questions/13201084/how-to-convert-a-kcvpixelformattype-420ypcbcr8biplanarfullrange-buffer-到uiimag?RQ = 1)。这可能有帮助。我会尝试一下并发布结果。 – d1xlord 2014-09-04 09:11:26