Question

I am using AVCaptureConnection and AVCaptureStillImageOutput class to create a overlay screen and capturing the image.In the view,I have a custom tab bar with some custom controls like capture button,flash button etc.

The problem is that the camera is capturing the whole image and it is seen in the preview page.i.e. the custom tabbar is of 40 pixels,so the user is shown the capture area with the tab bar.User takes the image till the custom tabbar.but in the preview screen,the image gets extended and he sees extra apart from the image he took.

I tried looking up for property in AVCaptureConnection to set the capture area but couldn't found anything.Anyone has faced the issue earlier,please help.1st screen where user takes the image

As you can see the user is seeing the extra apart from what he has taken

image that is taken

Was it helpful?

Solution

I don't think there is a way to set the capture area in AVCaptureConnection. Instead you could try to read the image off the screen and then crop it to your requirement.

If UIImage *photoImage is the image being returned on capturing the photo

CGRect refRect; //Define this to the exact frame which you want to crop the larger image to i.e. with smaller frame.size.height
CGFloat deviceScale = photoImage.scale;
CGImageRef imageRef = CGImageCreateWithImageInRect(photoImage.CGImage. refRect);
UIIImage *finalPhoto = [[UIImage alloc] initWithCGImage:imageRef deviceScale orientation:photoImage.imageOrientation];

The finalPhoto will now be cropped to what you want

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top