【发布时间】:2016-09-23 23:09:30
【问题描述】:
AVCapturePhotoOutput 是已弃用的 AVCaptureStillImageOutput 库,它允许在 iOS 10 中从视频连接中异步捕获静止图像。
【问题讨论】:
标签: avfoundation ios10
AVCapturePhotoOutput 是已弃用的 AVCaptureStillImageOutput 库,它允许在 iOS 10 中从视频连接中异步捕获静止图像。
【问题讨论】:
标签: avfoundation ios10
这不是AVCaptureStillImageOutput的简单替换。
查看the reference of AVCapturePhotoOutput:
特别是,您可能需要阅读概述中的这一部分:
- 通过将照片设置对象与委托对象一起传递给 capturePhoto(with:delegate:) 方法来捕获图像 实现 AVCapturePhotoCaptureDelegate 协议。照片 捕获输出然后调用你的代表通知你重要的 捕获过程中的事件。
实际代码示例可在 Apple 的示例代码中找到: AVCam-iOS
概括地说,您需要两个东西,一个AVCapturePhotoSettings 的实例和一个符合AVCapturePhotoCaptureDelegate 的实例。然后调用AVCapturePhotoOutput的capturePhoto(with:delegate:)方法。
let photoSettings = AVCapturePhotoSettings()
//setup `photoSettings`
//...
//create an instance conforming to `AVCapturePhotoCaptureDelegate`
let photoCaptureDelegate = PhotoCaptureDelegate(with: photoSettings,...)
//`AVCapturePhotoCaptureDelegate` can be a complex object, so in the sample code, implemented in a separate file as `PhotoCaptureDelegate`.
//You need to keep strong reference to the delegate instance while capturing in progress.
self.photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate)
示例代码包含一些您可能不需要的无关功能。您可以通过删除它们来简化它。
(您没有指定语言标签,但上面的示例代码包含 Objective-C 版本。)
使用这种委托方法,您可以获取图像,RAW 或 Live Photo 也存在类似的方法。
func capture(AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?)
【讨论】: