UIImage: Resize, then Crop

I’ve been bashing my face into this one for literally days now and even though I feel constantly that I am right on the edge of revelation, I simply cannot achieve my goal.

I thought, ahead of time in the conceptual phases of my design, that it would be a trivial matter to grab a image from the iPhone’s camera or library, scale it down to a specified height, using a function equivalent to the Aspect Fill option of UIImageView (entirely in code), and then crop off anything that did not fit within a passed CGRect.

Getting the original image from camera or library, was trivial. I am shocked at how difficult the other two steps have proved to be.

The attached image shows what I am trying to achieve. Would someone please be kind enough to hold my hand? Every code example I have found so far seems to smash the image, be upside down, look like crap, draw out of bounds, or otherwise just not work correctly.

16 Answers
16

Leave a Comment