0
votes

I'd like to capture only the image within the video preview layer. Currently, I set it like this:

[self setCaptureManager:[[[CaptureSessionManager alloc] init] autorelease]];
[[self captureManager] addVideoInputFrontCamera:YES]; // set to YES for Front Camera, No for Back camera
[[self captureManager] addStillImageOutput];

[[self captureManager] addVideoPreviewLayer];
CGRect layerRect = [[[self view] layer] bounds];
[[[self captureManager] previewLayer] setBounds:CGRectMake(0, 0, 320, 400)];//was layerRect
[[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))];// was CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))

[[[self view] layer] addSublayer:[[self captureManager] previewLayer]];

As it stands, the preview layer represents what I want to be captured, but the camera captures whatever is outside those bounds as well. I can't take a picture and crop it afterwards because the image isn't orientation up, so CGImageRef doesn't work. Is there anyway to capture just what's in the preview layer?

1

1 Answers

1
votes

This is not what the preview layer is supposed to do. If you need to take a picture you should use the stillImageOutput or the data buffer. According to the way you are capturing samples you shoul take care about the oreintation of the camera vs the device orientation. Orientation for jpg images is saved in a metadata dictionary called EXIF.
Apple has different samples code showing how to do still image capture. Here is also a blog post I've written about EXIF orientation.