5

我正在开发相机应用程序。我将 AVCapturePhotoOutput 用于 ios 10.x 设备,将 AVCaptureStillImageOutput 用于 10.x 以下设备。

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

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 的初学者。每次使用闪光灯模式成功拍摄照片后都会出现问题。

4

3 回答 3

-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。希望这可以帮助。

于 2017-06-14T07:23:50.780 回答
-1

苹果文档

如果闪光灯模式打开,您可能无法启用图像稳定功能。(启用闪光灯优先于 isAutoStillImageStabilizationEnabled 设置。)

不确定,如果它应该抛出错误,但你可以尝试删除这个字符串

settings.isAutoStillImageStabilizationEnabled = true
于 2017-06-08T08:32:54.530 回答