2012-03-31 3 views
1

イメージを撮影した直後にピクセルデータに直接アクセスしようとしています。 したがって、私はCVImageBufferRefが必要だと思うが、その常に0x00000000なぜ?あなたがAVCaptureStillImageOutputのoutputSettingsのキーkCVPixelBufferPixelFormatTypeKeyを設定する必要がcaptureStillImageAsynchronouslyFromConnectionでCVImageBufferRefを取得できませんか?

[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) 
{ 
    if(imageSampleBuffer){ 

     CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(imageSampleBuffer); 
     CVPixelBufferLockBaseAddress(pixelBuffer, 0); 

おかげ

+1

CMSampleBufferGetImageBufferをcaptureStillImageAsynchronouslyFromConnectionが返すCMSampleBufferRefで使用することはできないと思います。私が言うことができる限り、それはJPG形式であり、あなたはそれをティーンアウトする必要があります:NSData * imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];UIImage * image = [[UIImage alloc] initWithData:imageData]; //私は自分自身でより良い答えを見つけようとしています –

+0

同じ問題があって修正がうまくいきました、ありがとう!どのようにデモコードが動作するのかというと、それほど悲しいですか? – Cocoadelica

答えて

2

_stillImageOutput = [AVCaptureStillImageOutput new]; 
    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange], kCVPixelBufferPixelFormatTypeKey, nil]; 
    [_stillImageOutput setOutputSettings:outputSettings]; 

    if ([_captureSession canAddOutput:_stillImageOutput]) 
    [_captureSession addOutput:_stillImageOutput]; 

設定するには、2つの可能なキー(AVVideoCodecKey and kCVPixelBufferPixelFormatTypeKey)がありますが、相互に排他的です。 (iOS 6以降では、AVVideoCodecKeyを使用する場合は、画質キーAVVideoQualityKeyを設定することもできます)。

関連する問題