我试图用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)
}
}发布于 2020-01-16 05:49:41
有同样的问题,并且在另一个堆栈溢出线程上发现了这个,并补充说它对我来说是有效的:)
session.sessionPreset = AVCaptureSession.Preset.photo
下面是讨论的链接
AVCaptureSession is not giving a good photo quality and good resolution
希望这能有所帮助。
https://stackoverflow.com/questions/58967433
复制相似问题