Note that there are some explanatory texts on larger screens.

plurals
  1. POCapturing image preview as like as on the screen with AVFoundation
    primarykey
    data
    text
    <p>I set the <code>AVCaptureSession</code> preset PhotoPreset</p> <pre><code>self.session.sessionPreset = AVCaptureSessionPresetPhoto; </code></pre> <p>and then adding a new layer into my view with</p> <pre><code> AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session]; [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; CALayer *rootLayer = [self.view layer]; [rootLayer setMasksToBounds:YES]; [previewLayer setFrame:[rootLayer bounds]]; [rootLayer addSublayer:previewLayer]; </code></pre> <p>So far so good, However when I want to capture an image, I use the code below</p> <pre><code> AVCaptureConnection *videoConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo]; [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) { [self.session stopRunning]; NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; UIImage *image = [[UIImage alloc] initWithData:imageData ]; self.imageView.image = image; //IMAGEVIEW IS WITH THE BOUNDS OF SELF.VIEW image = nil; }]; </code></pre> <p>Capturing an image is fine however, the captured image is different comparing to <code>AVCaptureVideoPreviewLayer</code> showing on the screen. What I really want to do is to show captured as like as appearing on <code>AVCapturePreviewLayer</code> layer. How can I achieve this? How should I resize and crop the captured image with respect to the bounds of <code>self.view</code>? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload