我试图在拍摄图像后直接访问像素数据。 因此我想我需要CVImageBufferRef,但它总是0x00000000为什么?
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
if(imageSampleBuffer){
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(imageSampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
由于
答案 0 :(得分:2)
您必须设置kCVPixelBufferPixelFormatTypeKey
的outputSettings的键AVCaptureStillImageOutput
:
_stillImageOutput = [AVCaptureStillImageOutput new];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange], kCVPixelBufferPixelFormatTypeKey, nil];
[_stillImageOutput setOutputSettings:outputSettings];
if ([_captureSession canAddOutput:_stillImageOutput])
[_captureSession addOutput:_stillImageOutput];
要设置两个可能的键(AVVideoCodecKey and kCVPixelBufferPixelFormatTypeKey)
,但它们是互斥的。 (在iOS 6及更高版本中,如果使用AVVideoCodecKey,还可以设置图像质量键AVVideoQualityKey
。)