swift - 尝试使用 AVCapturePhotoOutput 捕获照片时图像变暗
问题描述
我正在尝试使用 AVCapturePhotoOutput 拍摄照片,但图像变暗了。这是我获取图像的方式
@IBAction func capturephoto(_ sender: Any) {
print("entered into capture photo")
let settings = AVCapturePhotoSettings()
let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first!
let previewFormat = [
kCVPixelBufferPixelFormatTypeKey as String: previewPixelType,
kCVPixelBufferWidthKey as String: self.preivew.frame.width,
kCVPixelBufferHeightKey as String: self.preivew.frame.height
] as [String : Any]
settings.previewPhotoFormat = previewFormat
captureSession.addOutput(stillImageOutput)
print("stillimageoutput is",stillImageOutput)
self.stillImageOutput.capturePhoto(with: settings, delegate: self)
}
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
if let error = error {
print(error.localizedDescription)
}
let imageData = photo.fileDataRepresentation()
if let data = imageData, let img = UIImage(data: data) {
print(img)
}
}
解决方案
有同样的问题,在另一个堆栈溢出线程上发现了这个问题,添加它对我有用:)
session.sessionPreset = AVCaptureSession.Preset.photo
这是讨论的链接
AVCaptureSession 没有提供良好的照片质量和良好的分辨率
希望这可以帮助。
推荐阅读
- css - 组织半表格网格,使列的宽度都相同
- python - 从列表创建字典
- docker - 如何从失败的 Docker 构建中检查最后一个好的层?
- r - 如何摆脱ggplot2地图周围的空白
- php - dompdf 排除菜单和页脚
- python - 将来自 for 循环的多个打印输出值存储到列表或变量中
- laravel - 如何用 eloquent 在 Laravel 中只获取一个用户数据?
- java - 当 JFrame 聚焦时(例如通过单击或使用 Alt+Tab),我如何设置聚焦的组件?
- recursion - 在递归数据类型(如 TREE)中实现公共属性
- google-cloud-firestore - Firestore 数据库结构问题在事务中更新多个文档