【发布时间】:2014-01-28 19:32:44
【问题描述】:
我正在尝试使用captureStillImageAsynchronouslyFromConnection 在循环中捕获连续(多张)高分辨率图像,但它偶尔会暂停以重新聚焦。我锁定了对焦模式(如其他 stackoverflow 帖子中所述),但这并没有阻止相机偶尔重新对焦。我的代码 sn-p 是:
// [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
表示焦点等应该已成功锁定。
我尝试用[device unlockForConfiguration] 和[device unlockForConfiguration] 包装锁码,但这并没有解决问题。
有人可以识别我的代码中的错误或我缺少的步骤吗? (我意识到我可以使用视频捕获而不是静态捕获来实现这一点,但我需要AVCaptureSessionPresetPhoto 分辨率图像。)任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: ios iphone cocoa-touch avfoundation avcapturesession