views:

129

answers:

1

I'm trying to implement tap to focus and tap to exposure in my iPhone app.

I'm using the AVFoundation camera interface and I'm having trouble moving between the 2 co-ord systems.

UIView uses a system that goes from (0,0) in the top left (in portrait mode) to (320,480) in the bottom right.

However the AVCaptureSession uses a system that goes from (0,0) in the top right to (1,1) in the bottom left.

I've had a look at the AVCamDemo but it doesn't seem to do anything to convert these, one minute you have the UIView coords and the next you have the AV coords.

Any help is appreciated!

Thanks

Oliver

A: 

OK, I worked out what was going on. I'm writing the app at home though so can't update during the day :(

Anyway, the coord system for the touch is from (0,0) to (320,480) (top left to bottom right in portrait mode).

The coord system for the focal point of interest is (0,0) to (1,1) (top left to bottom right in landscape right mode).

In order to get the tap to focus you'll need an AVCaptureVideoPreviewLayer embedded into a subclass of UIView. (I'm assuming in this that the view is displayed across the entire screen).

To get from a tap to a focal point do the following.

Get the tap CGPoint (e.g. tapPoint).

Then use...

CGPoint focalPoint = CGPointMake(tapPoint.y/480, (320 - tapPoint.x)/320);

There may be a bit of code that does this for you but until then this will suffice.

Fogmeister
This has to be done for each phone orientation.
Fogmeister