2017-06-05 171 views
5

我正在开发相机应用程序。我正在为10.x设备使用AVCapturePhotoOutput,对于10.x设备使用AVCaptureStillImageOutput。问题在拍摄照片时使用AVCapturePhotoOutput拍摄wtth闪光灯

我使用下面的拍摄设置,同时捕捉照片

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

+1

您是否可以复制并粘贴您收到的错误消息? – gwinyai

+0

我得到同样的错误。错误代码-16005错误descritption:操作无法完成。这个错误发生在每次成功捕获图像时闪光模式设置为 – 2017-06-06 03:31:32

+0

@Dhaval是否想要使用另一个类来捕获闪光灯图像? –

回答

-1

Apple documentation

如果闪光灯模式 上 你可能不使图像稳定。 (启用跳火 isAutoStillImageStabilizationEnabled 设置优先。)

不知道,如果它应该抛出错误,但你可以尝试删除该字符串

settings.isAutoStillImageStabilizationEnabled = true 
+0

通过评论'settings.isAutoStillImageStabilizationEnabled = true'来检查此行。仍然面临同样的问题。 –

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

+0

此解决方案适用于低于ios 10.x的版本现在AVCaptureStillImageOutput已弃用 –

+0

尽管已弃用AVCaptureStillImageOutput,但此方法仍可用于iOS 10.x版本。在发布答案之前,我已经在具有10.3.2的iOS版本的真实设备上测试了代码。 – Ayazmon