issue while taking photo wtth flash On using AVCapturePhotoOutput

1.6k Views Asked by At

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

I am using below capture settings while 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 am try to capture photo using above setting

captureOutput:didFinishProcessingPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error

above delegate throws error first time. I am beginner for AVCapturePhotoSettings. the problem is occurs after every successful photo capture with flash mode.

3

There are 3 best solutions below

1
On

From Apple documentation:

You may not enable image stabilization if the flash mode is on . (Enabling the flash takes priority over the isAutoStillImageStabilizationEnabled setting.)

Not sure, if it should throw error, but you can try to remove this string

settings.isAutoStillImageStabilizationEnabled = true
0
On
2
On

I'm using this method for handling the flash settings. AVCaptureDevice is basically the camera that you are using and the 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 you can set the flash setting to on, off or auto. Hope this helps.