I am try ing to take multiple pictures with iphone camera from the same scene programmatically and I don’t want the exposure or focus to change after the user sets it for the first picture.
Here is my code that gets executed when the use initiates the picture taking from within my app:
NSArray *devices = [AVCaptureDevice devices];
NSError *error;
for (AVCaptureDevice *device in devices) {
if (([device hasMediaType:AVMediaTypeVideo]) &&
([device position] == AVCaptureDevicePositionBack) ) {
[device lockForConfiguration:&error];
if ([device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked]) {
device.whiteBalanceMode = AVCaptureWhiteBalanceModeLocked;
NSLog(@"Whitebalanced locked");
}
if ([device isExposureModeSupported:AVCaptureExposureModeLocked]) {
device.exposureMode = AVCaptureExposureModeLocked;
NSLog(@"Exposure locked");
}
if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
device.focusMode = AVCaptureFocusModeLocked;
NSLog(@"Focus locked");
}
[device unlockForConfiguration];
}
}
The problem: Camera does auto-focus and auto-exposure after the first picture is taken. How can I force exposure and focus to stay locked?
Any help is appreciated.
I think you’re missing to commit the configuration:
Before your code put:
After:
Hope this helped.