AVCam with a square camera

I use AVCam to capture an image, but now I want to show a square camera and take a square image. How can i do this?

Many thanks!

+5
source share
1 answer

Those require two separate methods.

It is important to understand the difference between the two.

First, by changing the level of video preview, you need to adjust the gravity of the video. Note that this can be changed as follows, in the context of a full screen:

[Swift 3]

previewView.videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill 

Essentially, you are changing the boundaries of your viewfinder. However, you do not have any effect on the captured photo.

Now, for your situation of filling the square, you need to determine the boundaries of the layer, then use AVLayerVideoGravityResize .

Regarding the change of the captured image:

My method simply takes the returned image data, converts it to UIImage, and then performs the cropping operation. The fact is that your captured photo will always be the standard iPhone resolution and aspect ratio. You will need to take the image data and convert it at some point to remove the borders.

In truth, I no longer do this locally because it bothers. If you are talking to REST api, I would think that you are performing server side clipping operations - it is just as simple and without user overhead. Of course, this may not suit your situation.

0
source

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


All Articles