我正在尝试使用captureStillImageAsynchronouslyFromConnection
在循环中捕获连续的(多张)高分辨率图像,但它偶尔会暂停以重新对焦。我已经锁定了对焦模式(如其他stackoverflow帖子所述),但这并不能防止相机时不时地重新对焦。我的代码片段如下:
// [self.session beginConfiguration];
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");
}
}
// [self.session commitConfiguration];
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]
输出日志报告如下:
focus locked
exposure locked
white balance locked
这段代码中的
focus et al
表明焦点已成功锁定。我尝试使用
[device unlockForConfiguration]
和 [device unlockForConfiguration]
包装锁定代码,但这并没有解决问题。请问有人能够找出我的代码错误或者我遗漏了什么步骤吗?(我知道我也可以使用视频捕获代替静态捕获,但我需要
AVCaptureSessionPresetPhoto
分辨率的图像。)非常感谢任何帮助和支持。谢谢。