Reputation: 661
I am creating a camera app. I can take a image and the image is passing back to a view controller to show the image. It also saved to the camera roll. If I compare the image with the camera preview to the saved image, it seems like that the camera preview is a little bit zoomed in.
This is my code so far from the camera preview:
let cameraPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
cameraPreviewLayer.videoGravity = .resizeAspectFill
cameraPreviewLayer.connection?.videoOrientation = .portrait
cameraPreviewLayer.frame = view.frame
view.layer.insertSublayer(cameraPreviewLayer, at: 0)
captureSession.startRunning()
How can I make the camera preview to the same size as the saved image?
Upvotes: 1
Views: 1169
Reputation: 29
If you want the captured Image to have the same size as the camera preview. You should set videoGravity = .resize
Upvotes: 0
Reputation: 10398
The culprit is the videoGravity
setting. .resizeAspectFill
will resize the preview to fill the whole view, even when that means cropping content.
If you want to see the whole frame, set it to .resizeAspect
. This will introduce black bars, though.
Upvotes: 0