首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试使用AVCapturePhotoOutput捕获照片时图像变暗

尝试使用AVCapturePhotoOutput捕获照片时图像变暗
EN

Stack Overflow用户
提问于 2019-11-21 12:42:26
回答 1查看 160关注 0票数 1

我试图用AVCapturePhotoOutput捕捉照片,但图像变暗了。下面是我获取图像的方法

代码语言:javascript
复制
@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)
     }
 }
EN

回答 1

Stack Overflow用户

发布于 2020-01-16 05:49:41

有同样的问题,并且在另一个堆栈溢出线程上发现了这个,并补充说它对我来说是有效的:)

session.sessionPreset = AVCaptureSession.Preset.photo

下面是讨论的链接

AVCaptureSession is not giving a good photo quality and good resolution

希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58967433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档