khu*_*han 3 avfoundation ios10
AVCapturePhotoOutput是已弃用的AVCaptureStillImageOutput的库,该库允许从iOS 10中的视频连接异步捕获静态ImageA。
这不是的简单替代AVCaptureStillImageOutput。
特别是,您可能需要阅读概述中的这一部分:
- 通过将照片设置对象与实现AVCapturePhotoCaptureDelegate协议的委托对象一起传递给capturePhoto(with:delegate :)方法来捕获图像。然后,照片捕获输出将呼叫您的代表,以在捕获过程中将重大事件通知您。
实际的代码示例在Apple的示例代码中找到: AVCam-iOS
消化上,您需要两件事,一个实例AVCapturePhotoSettings和一个符合的实例AVCapturePhotoCaptureDelegate。然后调用的capturePhoto(with:delegate:)方法AVCapturePhotoOutput。
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)
Run Code Online (Sandbox Code Playgroud)
该示例代码将具有一些您可能不需要的无关功能。您可以通过删除它们来简化它。
(您没有指定语言标签,但是上面的示例代码包含Objective-C版本。)
使用这种委托方法,您可以获取图像,RAW或Live Photo也存在类似的方法。
func capture(AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3083 次 |
| 最近记录: |