I try to capture continuous (multi-tasking) high-resolution images using captureStillImageAsynchronouslyFromConnectionin a loop, but sometimes it pauses for reorientation. I blocked the focus mode (as described in other postoverflow postings), but this did not prevent the camera from refocusing periodically. My code snippet:
if ([device lockForConfiguration:nil] == YES) {
if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
[device setFocusMode:AVCaptureFocusModeLocked];
NSLog(@"focus locked");
}
if ([device isExposureModeSupported:AVCaptureExposureModeLocked]) {
[device setExposureMode:AVCaptureExposureModeLocked];
NSLog(@"exposure locked");
}
if ([device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked]) {
[device setWhiteBalanceMode:AVCaptureWhiteBalanceModeLocked];
NSLog(@"white balance locked");
}
}
for (int n = 0; n < 5; n++) {
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)image.imageOrientation completionBlock:nil];
}
}];
}
[device unlockForConfiguration]
Output Log Report:
focus locked
exposure locked
white balance locked
which indicates that focus and others should be successfully locked.
I tried to wrap the lock code with [device unlockForConfiguration]and [device unlockForConfiguration], but this did not fix the problem.
- - , ? ( , , , , AVCaptureSessionPresetPhoto.) . .