gpt4 book ai didi

avfoundation - iOS10:与 captureStillImageAsynchronouslyFromConnection 等效的 AVCapturePhotoOutput 是什么?

转载 作者:行者123 更新时间:2023-12-01 11:23:28 32 4
gpt4 key购买 nike

AVCapturePhotoOutput 是已弃用的 AVCaptureStillImageOutput 库,它允许从 iOS 10 中的视频连接中异步捕获静止图像。

最佳答案

这不是 AVCaptureStillImageOutput 的简单替换.

查看the reference of AVCapturePhotoOutput :

特别是,您可能需要阅读概述中的这一部分:

  1. Capture an image by passing your photo settings object to the capturePhoto(with:delegate:) method along with a delegate object implementing the AVCapturePhotoCaptureDelegate protocol. The photo capture output then calls your delegate to notify you of significant events during the capture process.


实际代码示例可在 Apple 的示例代码中找到:
AVCam-iOS

CameraViewController.swift

概括地说,你需要两个东西,一个 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-C 版本。)

使用这种委托(delegate)方法,您可以获取图像,RAW 或 Live Photo 也存在类似的方法。
func capture(AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?)

关于avfoundation - iOS10:与 captureStillImageAsynchronouslyFromConnection 等效的 AVCapturePhotoOutput 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39670784/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com