AVFoundation Camera preview screen gives incorrect zoom

I am currently developing an application that has camera functionality, with a custom camera screen, with a preview screen and overlay.

I use the AVFoundation classes and methods according to the destruction of UIScreenCapture.

The problem is that the preview data that I get from AVCaptureSession is too large. If I take a screenshot from this screen, and the other with the default iPhone app for iPhone, without moving the iPhone, the zoom difference is far too much.

I need to scale my application so that it is the same as the default for the iPhone app.

I tried changing AVCaptureVideoPreviewLayer.videoGravity to any of the three possible values, to no avail.

Please, any conclusions on this issue are truly appreciated.

+3
source share
3 answers

There was a question about permission. It has been fixed with

myCaptureSession.sessionPreset = AVCaptureSessionPreset640x480

Please note that iPhone 3G does not support this, so you need to ask if the device supports it

[[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] supportsAvCaptureSessionPreset:AVCaptureSessionPreset640x480]
+1
source

Arcantos's decision was basically the right one. This will work if you are on an iPhone 3G (or on any device with a camera that supports 640x480). The iPhone 4 may run into some problems.

A more correct way would be to check the availability and application of this preset:

captureSession.sessionPreset = AVCaptureSessionPresetPhoto;

, .

+2

Is the aspect ratio of your preview pane identical to the camera capture data format? If not, the OS can zoom to fit the data according to the requested aspect ratio.

0
source

Source: https://habr.com/ru/post/1763637/


All Articles