【问题标题】:issue while taking photo wtth flash On using AVCapturePhotoOutput使用 AVCapturePhotoOutput 使用闪光灯拍照时出现问题
【发布时间】:2017-06-05 13:40:37
【问题描述】:

我正在开发相机应用程序。我将 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 的初学者。每次使用闪光灯模式成功拍摄照片后都会出现此问题。

【问题讨论】:

  • 你能复制并粘贴你得到的错误信息吗?
  • 我遇到了同样的错误。错误代码 -16005 错误描述:操作无法完成。当 flashmode 设置为 On 时,每次成功捕获图像后都会出现此错误
  • @Dhaval 你想用另一个类来用闪光灯捕捉图像吗?
  • 我使用 AVCapturePhotoOutput for iOS 10.x 和 AVCaptureStillImageOutput。 AVCaptureStillImageOutput 适用于 10.x 以下的设备。 ios 10.x 设备中的 AVCapturePhotoOutput 出现问题。 AVCaptureStillImageOutput 现已弃用。
  • 在预览层停止渲染后使用 Flash 捕获时出现以下错误 :: (Error Domain=AVFoundationErrorDomain Code=-11800 \"无法完成操作\" UserInfo={NSUnderlyingError=0x174652060 {Error Domain=NSOSStatusErrorDomain Code=-16800 \"(null)\"}, NSLocalizedFailureReason=发生未知错误 (-16800), NSLocalizedDescription=操作无法完成})

标签: ios swift avcapturesession avcapturephotosettings


【解决方案1】:

来自Apple documentation

如果闪光灯模式为 在 . (启用闪光灯优先于 isAutoStillImageStabilizationEnabled 设置。)

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

settings.isAutoStillImageStabilizationEnabled = true

【讨论】:

  • 通过评论 settings.isAutoStillImageStabilizationEnabled = true 这一行进行检查。仍然面临同样的问题。
【解决方案2】:
【解决方案3】:

我正在使用这种方法来处理闪光灯设置。 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。希望这会有所帮助。

【讨论】:

  • 此解决方案适用于 ios 10.x 之前的版本,现在 AVCaptureStillImageOutput 已弃用
  • 即使 AVCaptureStillImageOutput 已被弃用,此方法仍可用于 iOS 10.x 版本。在发布答案之前,我已经在 iOS 版本为 10.3.2 的真实设备上测试了代码。
猜你喜欢
  • 1970-01-01
  • 2016-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多