Cropping and Resizing Images from Camera in iOS and Objective-C
I recently was working on an application for the iPhone and wanted to capture images using the built-in camera. I wanted to use something a little more advanced/customizable than the default ImagePicker, so I utilized the AVCaptureSession as detailed in this blog post from musicalgeometry.
When it came to viewing the images I had captured in the session, I quickly found out that they needed to have their orientation fixed and they needed to be scaled/cropped correctly. I had set up a square rect to use in the AVCaptureSession preview, so I wanted my final image to be displayed as a square. This function takes a UIImage and returns a UIImage that is scaled to the specified size and has the correct orientation.
This example is mostly taken from stackoverflow and other forum posts. While I found multiple solutions to this problem, I combined a few of them to make something that worked correctly on iOS 5+ and with the Retina screen. Some of the other solutions I found were for older versions of iOS or they made images look blurry on Retina devices.