开发者

Emulating the camera apps 'tap to focus'

I am trying hard to emulate the basic functionality of the built in camera app. Thus far I have become stuck on the 'tap to focus' feature.

I have a UIView from which I am collecting UITouch events when a single finger is tapped on the UIView. This following method is called but the camera focus & the exposure are unchanged.

-(void)handleFocus:(UITouch*)touch
{ 
     if( [camera lockF开发者_Go百科orConfiguration:nil] )
     {     
          CGPoint location = [touch locationInView:cameraView];

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

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


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

'camera' is my AVCaptureDevice & it is non-nil. Can someone perhaps tell me where I am going wrong?

Clues & boos all welcome.

M.


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

            }

        }        

    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜