我正在尝试创建一个基于AVFoundation框架的拍照应用程序。我有一个预览层在屏幕上,它充满了我想要的整个屏幕。
这是预览层看到的内容:https://ibb.co/47gYQbD
这是我捕获照片后得到的结果:https://ibb.co/qkkbf0N
下面是我创建预览层对象的方法。
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.videoGravity = .resizeAspectFill
previewLayer.frame = view.bounds
let previewLayerContainer = UIView()
previewLayerContainer.frame = CGRect(x: 0, y: 0, width: view.bounds.size.width, height: view.bounds.size.height)
view.addSubview(previewLayerContainer)
previewLayer.bounds = previewLayerContainer.bounds
previewLayerContainer.layer.addSublayer(previewLayer)照片设置:
// AVCapturePhotoSettings object
let photoSettings: AVCapturePhotoSettings
// Capture HEIF photos when supported
if self.photoOutput.availablePhotoCodecTypes.contains(.hevc) {
photoSettings = AVCapturePhotoSettings(format:
[AVVideoCodecKey: AVVideoCodecType.hevc])
} else {
photoSettings = AVCapturePhotoSettings()
}
//Enable auto-flash and high-resolution photos
if self.captureDeviceInput.device.isFlashAvailable {
switch currentFlashStatus {
case .AUTO:
photoSettings.flashMode = .auto
case .ON:
photoSettings.flashMode = .on
case .OFF:
photoSettings.flashMode = .off
}
}
photoSettings.isHighResolutionPhotoEnabled = true
//Photo Quality Prioritization
photoOutput.maxPhotoQualityPrioritization = .quality
photoSettings.photoQualityPrioritization = .quality发布于 2020-06-22 20:10:43
捕获的照片和您的屏幕具有不同的纵横比。当您告诉预览层为resizeAspectFill时,它将裁剪摄像机视频源的一部分以填充屏幕。如果要预览整个场景(以在预览中显示黑条为代价),请改用previewLayer.videoGravity = .resizeAspect。
https://stackoverflow.com/questions/62512872
复制相似问题