Dhaval Patel
Dhaval Patel

Reputation: 726

issue while taking photo wtth flash On using AVCapturePhotoOutput

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.

Upvotes: 6

Views: 1708

Answers (3)

Ayazmon
Ayazmon

Reputation: 1380

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.

Upvotes: -1

AVerguno
AVerguno

Reputation: 1377

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

Upvotes: -1

Related Questions