I let the user select a photo from the iPhone library, and I grab the UIImage.
I output the size of the image, and it says 320×480, but it doesn’t seem to be, because when I draw the image on the screen using CGRectMake(0,0,320,480), it only shows the upper left portion of the image. Aren’t the images much bigger than 320×480 because of the high resolution?
I’d like to scale the image to force it to be 320×480. If it is less than 320×480, it should not be rescaled at all. If the width is greater than 320 or the height is greater than 480, it should scale in a way so that it becomes as close to 320×480 as possible, but by keeping the proper proportion of width to height. So, for instance, if it scales to 320×420, that is fine, or 280×480.
How can I do this in Objective-C?
Setting the image view’s content mode like this:
will preserve the aspect ratio.