Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 尝试使用AVCapturePhotoOutput捕获照片时,图像变暗_Swift - Fatal编程技术网

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

Swift 尝试使用AVCapturePhotoOutput捕获照片时,图像变暗,swift,Swift,我正在尝试使用AVCapturePhotoOutput捕捉照片,但图像变暗。下面是我如何获得图像的 遇到同样的问题,并在另一个堆栈溢出线程上发现此问题,添加它对我有效:) session.sessionPreset=AVCaptureSession.Preset.photo 这里是讨论的链接 希望这有帮助 @IBAction func capturephoto(_ sender: Any) { print("entered into capture photo") let s

我正在尝试使用AVCapturePhotoOutput捕捉照片,但图像变暗。下面是我如何获得图像的


遇到同样的问题,并在另一个堆栈溢出线程上发现此问题,添加它对我有效:)

session.sessionPreset=AVCaptureSession.Preset.photo

这里是讨论的链接

希望这有帮助

@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)
     }
 }