AVCapturePhotoOutput是被废弃的AVCaptureStillImageOutput的库,它允许从iOS 10中的视频连接中捕获静止的ImageAsynchronously。
发布于 2016-09-23 23:47:16
这并不是AVCaptureStillImageOutput的简单替代。
特别是,您可能需要在概述中阅读此部分:
在苹果的示例代码中可以找到实际代码示例:AVCam
简单地说,您需要两样东西:一个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)示例代码将具有一些您可能不需要的无关特性。您可以通过删除它们来简化它。
(您没有指定语言标记,但上面的示例代码包含了Objective版本。)
使用此委托方法,您可以获取图像,对于RAW或Live也存在类似的方法。
func capture(AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?)https://stackoverflow.com/questions/39670784
复制相似问题