I am developing some kind of iOS app where I need to do some camera scan. This is my first experience with AVFoundation, I previously developed camera applications with the UIImagePickerController, but AVFoundation seems to be more powerful.
The problem is that it cuts off the edges in the preview level, regardless of the fact that I set the preview level frame to be larger than the preview controller.
This is my code:
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *photoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:photoCaptureDevice error:&error];
if(videoInput){
[captureSession addInput:videoInput];
[captureSession startRunning];
NSLog(@"ok");
}
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
previewLayer.frame = self.view.bounds;
NSLog(@"%f %f", previewLayer.frame.size.width, previewLayer.frame.size.height);
[self.view.layer addSublayer:previewLayer];
It would be very grateful for the help, Artem
Artem source
share