iOS: Creating a Custom Camera with AVFoundation

For a functionality in a current project, we needed a custom camera that took square pictures. After a decent amount of googling, it doesn’t seem like there is a pre-built functionality in AVFoundation that takes and output square photos. By default, all the preset Capture Session only allows the camera in the dimension of the screen.

Here was my idea as a workaround.

  1. Create two overlay frame of UIImageView, one top, one bottom.
  2. Size the two frame so it covers the Capture Session into a square, or whatever shape you are trying to get.
  3. Add a button to take the picture!
  4. Size the captured image to crop the designated area and shape.
Layout with the overlay frame, and capture button.

Code below!

Setting up the Camera!
Setting up Capture Button.
Process Image!
Final Product!
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.