首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将AVCaptureStillImageOutput修改为AVCapturePhotoOutput

将AVCaptureStillImageOutput修改为AVCapturePhotoOutput
EN

Stack Overflow用户
提问于 2017-01-01 22:05:24
回答 1查看 1.7K关注 0票数 0

我目前正在编写代码片段,如下所示:

代码语言:javascript
复制
if error == nil && (captureSession?.canAddInput(input))!
{
    captureSession?.addInput(input)

    stillImageOutput = AVCaptureStillImageOutput()
    //let settings = AVCapturePhotoSettings()
    //settings.availablePreviewPhotoPixelFormatTypes =
    stillImageOutput?.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG]

    if (captureSession?.canAddOutput(stillImageOutput))!
    {
        captureSession?.addOutput(stillImageOutput)

        previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
        previewLayer?.videoGravity = AVLayerVideoGravityResizeAspect
        previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.portrait
        cameraView.layer.addSublayer(previewLayer!)
        captureSession?.startRunning()
    }
}

我知道我应该使用AVCapturePhotoOutput()而不是AVCaptureStillImageOutput(),但是如果我做了这样的更改,我会对如何转换这个块的其余部分感到困惑。

具体来说,如何使用注释的let settings = AVCapturePhotoSettings()应用相同的设置?

作为参考,我正在使用教程作为指南。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-02 05:44:50

苹果文档对AVCapturePhotoOutput的解释非常清楚

以下是拍摄照片的步骤。

  • 创建一个AVCapturePhotoOutput对象。使用其属性确定支持的捕获设置,并启用某些功能(例如,是否捕获Live )。
  • 创建并配置AVCapturePhotoSettings对象,以选择特定捕获的特性和设置(例如,是启用图像稳定还是闪存)。
  • 通过将照片设置对象传递给capturePhoto( with::)方法以及实现AVCapturePhotoCaptureDelegate协议的委托对象来捕获图像。然后,照片捕获输出调用您的委托,通知您在捕获过程中发生的重大事件。

在您的clickCapture方法中使用下面的代码,并且不要忘记在类中确认和实现委托。

代码语言:javascript
复制
let settings = AVCapturePhotoSettings()
let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first!
let previewFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewPixelType,
                             kCVPixelBufferWidthKey as String: 160,
                             kCVPixelBufferHeightKey as String: 160,
                             ]
settings.previewPhotoFormat = previewFormat
self.cameraOutput.capturePhoto(with: settings, delegate: self)

如果您想知道从avfoundation获取照片的不同方法,请查看我之前的SO 回答

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41419453

复制
相关文章

相似问题

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