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。

4

1 回答 1

27

This snippet might help you...There is a CamDemo provided by apple floating around which allows you to focus, change exposure while tapping, set flash, swap cameras and more, it emulates the camera app pretty well, not sure if youll be able to find it since it was part of wwdc, but if u leave some email address in the comments i can email you the sample code...

- (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];

            }

        }        

    }

}
于 2010-07-27T18:39:06.777 回答