2014-10-11 27 views
3

之後的奇怪行爲我正在研究一個應用程序,該應用程序使用iOS 8中引入的新API公開了相機的手動控件,並且我將這個來自WWDC 2014的sample app用作參考。修改曝光持續時間並返回到AVCaptureExposureModeContinuousAutoExposure

但是我注意到一個奇怪的bahaviour(在我的5s和6上):在將曝光模式設置爲「custom」並且然後回到「auto」之後,圖像繼續滯後,就好像曝光持續時間不受這個變化。

bug

這裏是涉及每個步驟中的代碼(從樣品應用程序,而沒有任何修改):

- (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); 
    } 
} 
+0

嘗試在CGD主線程中添加所有的兩個方法代碼..可以幫助.... – hmdeep 2014-10-11 09:25:44

回答

0

我注意到這一點。這似乎與低速快門有關。試試這個:去定製。設置快門速度。然後回到自動。轟隆,你就在那裏。現在,進入自定義,設置一個慢快門速度(滑塊向右)。回到自動,您可以觀看快門速度逐漸回到合理的設置。

這是示例代碼和我基於示例代碼編寫的應用程序中的情況。我的4和5也是一樣的。

我相信這是因爲傳感器需要捕捉一定數量的圖像才能選擇正確的自動設置。如果快門速度非常慢(最長可達1秒),這意味着可能需要幾秒鐘才能找到正確的設置。有點意義,即使不是我們想要的。對我來說幸運的是,如果那樣的話,我的應用從來不需要超過四分之一秒的快門速度。

0

我在我自己的代碼中發現setExposureModeCustomWithDuration方法有一些問題。雖然它有一個完成處理程序,它應該在設備中設置持續時間和ISO後調用,但它並不總是有效。 有時候,例如從自動曝光切換到手動曝光時,如果您從setExposureModeCustomWithDuration的完成處理程序中獲取靜物,則會使用自動曝光設置拍攝靜物。如果在此之後再拍攝其他照片,則會在其上設置正確的手動曝光。

我發現,在完成處理的開始延遲1秒解決了這個問題,但不能成爲一個妥善的解決辦法。

我也曾嘗試把等待/睡眠循環在這裏等到設備不調整曝光完成處理的開始 - 這並沒有幫助。

+0

你到底是如何解決這個問題的。我甚至嘗試延遲5秒,仍然是第一張照片是錯誤的。請與我們分享。 – manta 2016-09-30 21:56:17

0

我嘗試過同樣的示例應用程序,並試圖重現該問題,但無法看起來他們現在已經修好了。