Problem with flash photography When using AVCapturePhotoOutput

I am working on a camera. I am using AVCapturePhotoOutput for an ios 10.x device and AVCaptureStillImageOutput for below 10.x devices.

I use below capture settings when capturing Photo

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) 

when I try to capture a photo using the above setting

 captureOutput:didFinishProcessingPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error 

above the delegate gives an error the first time. I am starting for AVCapturePhotoSettings. The problem occurs after each successful capture of photos in flash mode.

+5
source share
3 answers

From Apple Documentation :

You cannot turn on image stabilization if the flash mode is on, (Turning on the flash takes precedence over the isAutoStillImageStabilizationEnabled setting.)

Not sure if it should cause an error, but you can try to delete this line

 settings.isAutoStillImageStabilizationEnabled = true 
-1
source

I use this method to handle flash settings. AVCaptureDevice is basically the camera you use, and AVCaptureFlashMode is the flash mode you want to use.

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

With this option, you can set the flash setting to on , off or auto . Hope this helps.

-1
source

Source: https://habr.com/ru/post/1268555/


All Articles