首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >captureStillImageAsynchronouslyFromConnection?的AVCapturePhotoOutput等价于什么?

captureStillImageAsynchronouslyFromConnection?的AVCapturePhotoOutput等价于什么?
EN

Stack Overflow用户
提问于 2016-09-23 23:09:30
回答 1查看 3.7K关注 0票数 4

AVCapturePhotoOutput是被废弃的AVCaptureStillImageOutput的库,它允许从iOS 10中的视频连接中捕获静止的ImageAsynchronously。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-23 23:47:16

这并不是AVCaptureStillImageOutput的简单替代。

检查AVCapturePhotoOutput

特别是,您可能需要在概述中阅读此部分:

  1. 通过将照片设置对象传递给capturePhoto( with::)方法以及实现AVCapturePhotoCaptureDelegate协议的委托对象来捕获图像。然后,照片捕获输出调用您的委托,通知您在捕获过程中发生的重大事件。

在苹果的示例代码中可以找到实际代码示例:AVCam

请参阅CameraViewController.swift

简单地说,您需要两样东西:一个AVCapturePhotoSettings实例和一个符合AVCapturePhotoCaptureDelegate的实例。然后调用capturePhoto(with:delegate:)方法的AVCapturePhotoOutput

代码语言:javascript
复制
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也存在类似的方法。

代码语言:javascript
复制
func capture(AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39670784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档