我目前正在编写代码片段,如下所示:
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()应用相同的设置?
作为参考,我正在使用这教程作为指南。
谢谢
发布于 2017-01-02 05:44:50
苹果文档对AVCapturePhotoOutput的解释非常清楚
以下是拍摄照片的步骤。
在您的clickCapture方法中使用下面的代码,并且不要忘记在类中确认和实现委托。
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 回答
https://stackoverflow.com/questions/41419453
复制相似问题