Rolando Rodríguez
1 min readFeb 1, 2021

--

Hi Madhav, thank you for reading! I'm glad you enjoyed the article. Regarding your question, remember, image capturing is actually performed individually from the UI, it's a process SwiftUI is not responsible of -- having that in mind, the problem you propose can be splited in two:

1) UI: How the camera preview is shown.

2) Processed capture: What final aspect ratio or size the photos are being output at.

For the first one, we should check the CameraPreview implementation and change the videoPreviewLayer's videogravity to resizeAspectFill. Then resize the SwiftUI view representing the camera preview to fit the size you like, using the .frame() modifier.

Regarding the second one, you'll need to do some post processing after capturing the photo, probably some cropping since the original aspect ratio of the captured photos is 4:3, and the target one in your case is 1:1.

For that this might be helpful: https://developer.apple.com/documentation/coregraphics/cgimage/1454683-cropping

Cheers!

--

--

Rolando Rodríguez
Rolando Rodríguez

Written by Rolando Rodríguez

I’m a software engineer, l code and design some stuff 👨🏾‍💻

No responses yet