拍摄照片时使用AVCapturePhotoOutput拍摄重量闪光问题

时间:2017-06-05 13:40:37

标签: ios swift avcapturesession avcapturephotosettings

我正在开发相机应用程序。我正在为ios 10.x设备使用AVCapturePhotoOutput,为10.x设备使用AVCaptureStillImageOutput。

我在拍摄照片时使用下面的拍摄设置

let settings = AVCapturePhotoSettings()

let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first!
        let previewFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewPixelType,
                             kCVPixelBufferWidthKey as String: 1080,
                             kCVPixelBufferHeightKey as String: 1080,
                             ]
settings.previewPhotoFormat = previewFormat
settings.isHighResolutionPhotoEnabled = true
settings.flashMode = .on
settings.isAutoStillImageStabilizationEnabled = true
self.captureOutputPhoto?.capturePhoto(with: settings, delegate: self)

当我尝试使用上述设置拍摄照片时

captureOutput:didFinishProcessingPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error

以上委托首次抛出错误。我是AVCapturePhotoSettings的初学者。使用闪光模式拍摄每张成功照片后都会出现此问题。

3 个答案:

答案 0 :(得分:-1)

来自Apple documentation

  

如果闪光模式为,则可能无法启用图像稳定功能   上   。 (启用闪存优先于   isAutoStillImageStabilizationEnabled    设置。)

不确定,是否应该抛出错误,但您可以尝试删除此字符串

settings.isAutoStillImageStabilizationEnabled = true

答案 1 :(得分:-1)

答案 2 :(得分:-1)

我使用此方法处理闪光灯设置。 AVCaptureDevice基本上是您正在使用的相机,AVCaptureFlashMode是您要使用的闪光模式。

func changeFlashSettings(device: AVCaptureDevice, mode: AVCaptureFlashMode) {
    do {
        try device.lockForConfiguration()
        device.flashMode = mode
        device.unlockForConfiguration()
    } catch {
        print("Change Flash Configuration Error: \(error)")
    }
}

使用此功能,您可以将闪光设置设为onoffauto。希望这会有所帮助。