为什么AVCaptureStillImageOutput jpegStillImageNSDataRepresentation会抛出一个带有NULL样本缓冲区的异常?

时间:2011-12-09 21:43:46

标签: iphone ios

NSInvalidArgumentException * + [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - NULL样本缓冲区。

如果您连续拍摄太多(太快)的照片,这似乎就会发生。

2 个答案:

答案 0 :(得分:10)

它在文档中说:

  

如果jpegSampleBuffer为NULL或者不是JPEG格式,则此方法抛出NSInvalidArgumentException。

所以这可能意味着JPEG处理器所期望的数据还没有在缓冲区中(如果你拍的太快了)。

因此,要么检查imageSampleBuffer NULL还是我做了什么:我将整个事情包装在if语句中检查:CMSampleBufferIsValid(imageSampleBuffer)但是不知道是不是保护这一点的正确方法。文档有点稀疏。

答案 1 :(得分:4)

像往常一样,检查错误。

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

同样只是来,这里是(IBAction)didTakePhoto

if (self.captureSession.isRunning) {
    [self captureNow];
        //Custom capture method.
}