@IBAction func clickPicture(_ sender: UIButton) {
let photoSettings = AVCapturePhotoSettings()
photoSettings.flashMode = .auto
photoSettings.isHighResolutionPhotoEnabled = true
if photoSettings.availablePreviewPhotoPixelFormatTypes.count > 0 {
photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String : photoSettings.availablePreviewPhotoPixelFormatTypes.first!]
}
self.wideAngleOutPut.capturePhoto(with: photoSettings, delegate: self)
}
当我在上面调用函数来捕获图像应用程序时抛出异常:self.wideAngleOutPut.capturePhoto(with: photoSettings, delegate: self)
在日志部分中,我可以看到更多详细信息中的错误:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'* ** - [AVCapturePhotoOutput capturePhotoWithSettings:delegate:]如果在设置中指定了非零格式字典,则代理必须回应选择器****
有人可以帮忙吗?提前谢谢。
答案 0 :(得分:1)
如果设置了previewPhotoFormat,则需要在委托中实现以下内容。
func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?)
我猜这是因为这是在这种情况下访问预览的唯一方法。