之後的奇怪行爲我正在研究一個應用程序,該應用程序使用iOS 8中引入的新API公開了相機的手動控件,並且我將這個來自WWDC 2014的sample app用作參考。修改曝光持續時間並返回到AVCaptureExposureModeContinuousAutoExposure
但是我注意到一個奇怪的bahaviour(在我的5s和6上):在將曝光模式設置爲「custom」並且然後回到「auto」之後,圖像繼續滯後,就好像曝光持續時間不受這個變化。
這裏是涉及每個步驟中的代碼(從樣品應用程序,而沒有任何修改):
- (IBAction)changeExposureMode:(id)sender
{
UISegmentedControl *control = sender;
NSError *error = nil;
AVCaptureExposureMode mode = (AVCaptureExposureMode)[self.exposureModes[control.selectedSegmentIndex] intValue];
if ([self.videoDevice lockForConfiguration:&error])
{
if ([self.videoDevice isExposureModeSupported:mode])
{
[self.videoDevice setExposureMode:mode];
}
else
{
NSLog(@"Exposure mode %@ is not supported. Exposure mode is %@.", [self stringFromExposureMode:mode], [self stringFromExposureMode:self.videoDevice.exposureMode]);
}
}
else
{
NSLog(@"%@", error);
}
}
- (IBAction)changeExposureDuration:(id)sender
{
UISlider *control = sender;
NSError *error = nil;
double p = pow(control.value, EXPOSURE_DURATION_POWER); // Apply power function to expand slider's low-end range
double minDurationSeconds = MAX(CMTimeGetSeconds(self.videoDevice.activeFormat.minExposureDuration), EXPOSURE_MINIMUM_DURATION);
double maxDurationSeconds = CMTimeGetSeconds(self.videoDevice.activeFormat.maxExposureDuration);
double newDurationSeconds = p * (maxDurationSeconds - minDurationSeconds) + minDurationSeconds; // Scale from 0-1 slider range to actual duration
if (self.videoDevice.exposureMode == AVCaptureExposureModeCustom)
{
if (newDurationSeconds < 1)
{
int digits = MAX(0, 2 + floor(log10(newDurationSeconds)));
self.exposureDurationValueLabel.text = [NSString stringWithFormat:@"1/%.*f", digits, 1/newDurationSeconds];
}
else
{
self.exposureDurationValueLabel.text = [NSString stringWithFormat:@"%.2f", newDurationSeconds];
}
}
if ([self.videoDevice lockForConfiguration:&error])
{
[self.videoDevice setExposureModeCustomWithDuration:CMTimeMakeWithSeconds(newDurationSeconds, 1000*1000*1000) ISO:AVCaptureISOCurrent completionHandler:nil];
}
else
{
NSLog(@"%@", error);
}
}
嘗試在CGD主線程中添加所有的兩個方法代碼..可以幫助.... – hmdeep 2014-10-11 09:25:44