views:

505

answers:

2

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 lockForConfiguration: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.

+1  A: 

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

            }

        }        

    }

}
Daniel
I'd be very glad for that source code. Catch me at codehammer <at> suremail <dot> info.My thanks again.
Martin Cowie
alright, sent .
Daniel
@Martin Cowie - Actually, the source code is available as part of the WWDC 2010 videos. Simply login to get the videos, go to iTunes, and a link to download the sample code will appear in the upper-right: http://developer.apple.com/videos/wwdc/2010/ You will be looking for the AVCam and AVCamDemo sample applications, I believe.
Brad Larson
@Brad Larson - Good heavens! Enough sample code to keep me happy for a good while. Thanks Brad!
Martin Cowie
A: 

I do not see that code working at all on my 3gs. I tried camera app as well as AVCamDemo. The tap to focus of camera app works well, while it does not work in AVCamDemo sample app. Please help!

Deepak Sharma