I'm developing an iPhone application in which I have to use AVCaptureSession to capture an image from the rear Camera. Each time the application starts, it will receive 2 values from a server, the first value is the AVCaptureSession's sessionPreset property, and the second is a GCRect for clipping the output image (the coordinate of this rectangle is corresponding to the output image's resolution).
Now the problem is, I have to "draw" that clipping rectangle onto the camera preview, which means I'll have to map the coordinate of the clipping rectangle to another "proper" coordinate of the camera preview (since the sessionPreset varies each time the application starts). I've search on Apple's documentation but I couldn't find a way to get the resolution of the output image. I need that output resolution in order to do the clipping rectangle's mapping.
This is the code where I start my AVCaptureSession in my view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
//Capture Session
AVCaptureSession *session = [[AVCaptureSession alloc]init];
session.sessionPreset = _sessionPreset; //this _sessionPreset varies each time my app starts
//Add device
AVCaptureDevice *device =
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//Input
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
if (!input)
{
NSLog(@"No Input");
}
[session addInput:input];
//Output
AVCaptureStillImageOutput *output = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil];
[output setOutputSettings:outputSettings];
[session addOutput:output];
//Preview Layer
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
UIView *myView = self.view;
previewLayer.frame = myView.bounds;
previewLayer.videoGravity = AVLayerVideoGravityResizeAspect;
[self.view.layer addSublayer:previewLayer];
//Start capture session
[session startRunning];
//Now I want to draw the rectangle after the session starts
}
Thanks in advance fellas :)