【发布时间】:2017-09-09 23:15:13
【问题描述】:
我正在尝试在我的应用中实现一项功能,该功能允许用户拍摄个人资料照片。使用 AVFoundation,我可以轻松地将视频预览层输出到全屏。我也尝试将预览层框架设置为 imageview 框架,但它给了我下图所示的结果。
if let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession){
self.previewLayer = previewLayer
//this is for full screen output
//self.view.layer.addSublayer(self.previewLayer)
//self.previewLayer.frame = self.view.layer.frame
//this gives me the result in the photo
cameraOutputImageView.layer.addSublayer(self.previewLayer)
self.previewLayer.frame = cameraOutputImageView.layer.frame
captureSession.startRunning()
print("trying to run capture session")
let dataOutput = AVCaptureVideoDataOutput()
dataOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString):NSNumber(value: kCVPixelFormatType_32BGRA)]
dataOutput.alwaysDiscardsLateVideoFrames = true
if captureSession.canAddOutput(dataOutput){
captureSession.addOutput(dataOutput)
}
captureSession.commitConfiguration()
}
但是,我希望视频源是一个正方形,它与要填充的图像视图的大小相同。这是它现在的样子:
粉红色的框是需要用图像填充的。现在它只显示左上角附近的相机输出
【问题讨论】:
标签: ios swift camera avfoundation