Reputation: 726
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
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
Reputation: 5618
captureOutput:didFinishProcessingPhotoSampleBuffer:previewPhotoSampleBuffer:resolvedSettings:bracketSettings:error:
, an Objective-C delegate method, whose Swift version is photoOutput(_:didFinishProcessingPhoto:previewPhoto:resolvedSettings:bracketSettings:error:)
, is deprecated.
Instead implement the Swift method photoOutput(_:didFinishProcessingPhoto:error:)
.
Upvotes: -1
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