5

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.

Dhaval Patel
  • 716
  • 1
  • 10
  • 26
  • 1
    Can you copy and paste the error message you are getting? – gwinyai Jun 05 '17 at 13:59
  • I am getting same error. error code -16005 error descritption : operation could not completed. this error comes after every successful image capture when flashmode set On –  Jun 06 '17 at 03:31
  • @Dhaval did you want to use another class for capture image with flash ? – Himanshu Moradiya Jun 09 '17 at 06:14
  • i am used AVCapturePhotoOutput for iOS 10.x and AVCaptureStillImageOutput. AVCaptureStillImageOutput working properly for below 10.x devices. problem comes with AVCapturePhotoOutput in ios 10.x devices. AVCaptureStillImageOutput now deprecated. – Dhaval Patel Jun 09 '17 at 06:51
  • below error comes while capture with flash after that preview layer stop rendering :: (Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not be completed\" UserInfo={NSUnderlyingError=0x174652060 {Error Domain=NSOSStatusErrorDomain Code=-16800 \"(null)\"}, NSLocalizedFailureReason=An unknown error occurred (-16800), NSLocalizedDescription=The operation could not be completed}) – Dhaval Patel Jun 13 '17 at 06:20

3 Answers3

-1

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
AVerguno
  • 1,277
  • 11
  • 27
-1

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.

Ayazmon
  • 1,360
  • 8
  • 17
  • this solution is working for perior than ios 10.x now AVCaptureStillImageOutput is deprecated – Dhaval Patel Jun 16 '17 at 13:30
  • Even though AVCaptureStillImageOutput is deprecated this method still can be used for iOS 10.x versions. Before posting the answer I have tested the code on a real device that has the iOS version of 10.3.2. – Ayazmon Jun 16 '17 at 14:32