在iOS中,我使用的代码从AVCaptureStillImageOutput从而捕捉:为什么样本缓冲区不为空时jpegStillImageNSDataRepresentation会引发异常?
[_captureStillOutput captureStillImageAsynchronouslyFromConnection:_captureConnection completionHandler:asyncCaptureCompletionHandler];
为了简单归结我的代码,我asyncCaptureCompletionHandler块看起来是这样的:
void(^asyncCaptureCompletionHandler)(CMSampleBufferRef imageDataSampleBuffer, NSError *error) =
^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (CMSampleBufferIsValid(imageDataSampleBuffer)) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
}
}
我已经通过我的所有代码与跨堆栈溢出引用,并没有发现任何建议,为什么一个有效样本缓冲区将被捕获而不是正确的JPEG。
_captureStillOutput = [[AVCaptureStillImageOutput alloc] init];
_captureStillOutput.outputSettings =
[NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecJPEG, AVVideoCodecKey,
nil];
if ([session canAddOutput:_captureStillOutput]) {
[session addOutput:_captureStillOutput];
}
有一个在调试器的补充信息: *终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因: '* + [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - 不是JPEG样品缓冲液'。
谷歌和堆栈溢出搜索“不是一个jpeg样本缓冲区”产生零结果。我卡住了。呸。
可以确认,一个好的“rm -rf DerivedData/*”并重新启动Xcode为我解决了这个问题。 – Austin
事实上,问题再次出现,但当我关闭iTunes后便消失了。这是一个非常疯狂的 – Austin
谢谢你的注意,它再次出现,然后再次消失。 –