【发布时间】:2013-03-22 14:30:39
【问题描述】:
我需要从 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 或其他第 3 方。
【问题讨论】:
-
SO上有很多类似的问题和解决方案。
-
@Jeepston 找不到任何可用于静止图像的工作...
标签: ios objective-c avfoundation cmsamplebufferref