2011-08-11 93 views
3

我使用avfoundation捕獲圖像,但我無法快速捕獲(我將間隔時間設置爲0.1s)。它說「NULL樣本緩衝區」。問題是什麼?謝謝。使用avfoundation捕獲圖像,但不能捕獲得太快

[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) 
{ 
    CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL); 
    if (exifAttachments) 
    { 
     // Do something with the attachments. 
     // NSLog(@"attachements: %@", exifAttachments); 
    } 
    else 
     NSLog(@"no attachments"); 

    NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; 
    UIImage *image = [[UIImage alloc] initWithData:imageData]; 
    //use the image 
}]; 

*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因: '* + [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - NULL樣品緩衝液'。

+0

面臨同樣的問題,你能解決這個問題嗎? – BaSha

回答

2

那麼它說,在文檔中:

此方法拋出NSInvalidArgumentException如果jpegSampleBuffer是JPEG格式NULL與否。

因此,無論您檢查imageSampleBufferNULL或我做什麼,我包了整個事情的if語句檢查:CMSampleBufferIsValid(imageSampleBuffer),但真的不知道這是否是正確的調用。文檔有點稀疏。

0

事情幫助我現在的問題是

[helper captureImage]; 

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ 
     [scheduledTimer invalidate]; 
     [helper stopRunningSession]; 


     imageView.image = helper.imageToReturn; 
    }); 

這裏我使用一個輔助類來運行會話和定時器來獲得圖像的幀。所以起初我打電話給我的捕捉圖像功能,延遲0.3秒後。我使計時器無效並停止AVCaptureSession

相關問題