我需要从CMSampleBufferRef中的未压缩图像数据获取UIImage
。我使用以下代码:
captureStillImageOutput captureStillImageAsynchronouslyFromConnection:connection
completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
// that famous function from Apple docs found on a lot of websites
// does NOT work for still images
UIImage *capturedImage = [self imageFromSampleBuffer:imageSampleBuffer];
}
http://developer.apple.com/library/ios/#qa/qa1702/_index.html 是一个指向imageFromSampleBuffer
函数的链接。但是它不能正常工作。:(
有一个
jpegStillImageNSDataRepresentation:imageSampleBuffer
方法,但它只提供了压缩数据(因为是JPEG)。我怎样才能获得用于捕获静态图像后创建的最原始的非压缩数据的
UIImage
?也许,我应该为视频输出指定一些设置?我目前正在使用以下设置:
captureStillImageOutput = [[AVCaptureStillImageOutput alloc] init];
captureStillImageOutput.outputSettings = @{ (id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA) };
我注意到,输出的
AVVideoCodecKey
有一个默认值,即AVVideoCodecJPEG
。有没有什么方法可以避免它呢?或者在捕捉静态图像时是否重要?我在这里找到了一些内容:Raw image data from camera like "645 PRO",但我只需要一个UIImage,不使用OpenCV、OGLES或其他第三方库。