Reputation: 4032
I'll start with saying that I am new to objective-c and iOS-programming.
What I want to do is to display camera as a part of a view, like a rectangle in the upper part of a screen, where should I start?
(What GUI-component for the "camera view"? AVCamCaptureManager
or UIImagePickerController
?)
Upvotes: 3
Views: 1423
Reputation: 528
You can use the AVFoundation to do that. A good starting point is to see the WWDC videos (since 2011) related with AVFoundation and Camera.
The Apple's example code for AVCam project is a very good starting point.
Here's an example of what you can do.
First you need to instantiate a capture session:
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPreset1280x720;
Then you must create the input and add it to the session in order to get images from your device camera:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
NSLog(@"Couldn't create video capture device");
}
[session addInput:input];
Then you make use of AVCaptureVideoPreviewLayer to present in a Layer the images from your device camera:
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
Finally you just need to set the frame (portion of UI you need) of that specific layer and add it to the desired view and start the session capture.
Upvotes: 4