2010-07-27 26 views
18

我正在努力模擬內置相機應用程序的基本功能。到目前爲止,我已經停留在「點擊聚焦」功能上。模擬相機應用程序的點擊重點'

我有一個UIView,當我在UIView上點擊一個手指時,我正在收集UITouch事件。調用以下方法,但相機焦點&曝光不變。

-(void)handleFocus:(UITouch*)touch 
{ 
    if([camera lockForConfiguration:nil]) 
    {  
      CGPoint location = [touch locationInView:cameraView]; 

      if([camera isFocusPointOfInterestSupported]) 
       camera.focusPointOfInterest = location; 

      if([camera isExposurePointOfInterestSupported]) 
       camera.exposurePointOfInterest = location; 


      [camera unlockForConfiguration]; 
      [cameraView animFocus:location]; 
    } 
} 

'攝像頭' 是我AVCaptureDevice &它是非零。有人可能會告訴我我哪裏出錯了嗎?

線索&噓聲都歡迎。

M.

+1

還記得那兩個exposurePointOfInterest和focusPointOfInterest是(0,0)和(1,1)之間的CGPoint。無論設備的方向如何,(0,0)是左上角,(1,1)是設備在右側方向的右下角。因此,使用'camera.focusPointOfInterest = location'將不會得到你想要的結果。 – 2014-01-16 23:27:24

回答

27

這個片段可以幫助你...有蘋果漂浮提供CamDemo圍繞讓你集中精力,改變曝光而攻,設置閃光燈,交換相機和更多的,它模擬攝像機應用得很好,不知道你會能找到它,因爲它是WWDC的一部分,但如果u在評論中留下一些電子郵件地址,我可以向您發送電子郵件的示例代碼...

- (void) focusAtPoint:(CGPoint)point 

{ 

    AVCaptureDevice *device = [[self videoInput] device]; 

    if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) { 

     NSError *error; 

     if ([device lockForConfiguration:&error]) { 

      [device setFocusPointOfInterest:point]; 

      [device setFocusMode:AVCaptureFocusModeAutoFocus]; 

      [device unlockForConfiguration]; 

     } else { 

      id delegate = [self delegate]; 

      if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) { 

       [delegate acquiringDeviceLockFailedWithError:error]; 

      } 

     }   

    } 

} 
+0

我會很高興爲那個源代碼。趕上codehammer suremail info。 我再次感謝。 – 2010-07-27 19:30:50

+0

好吧,發送。 – Daniel 2010-07-27 19:41:14

+3

@Martin Cowie - 實際上,源代碼可作爲WWDC 2010視頻的一部分。只需登錄即可獲取視頻,轉到iTunes,下載示例代碼的鏈接將出現在右上角:http://developer.apple.com/videos/wwdc/2010/您將在尋找AVCam和AVCamDemo示例應用程序,我相信。 – 2010-07-27 22:41:08