Preserving the Aspect Ratio


I have managed to preserve the aspect ratio, but I have no idea if this is the best solution. Frankly, I think it’s a bad way to go, but I don’t really have a clue at an alternative method.

Here’s what I’ve come up with; if someone else has a better idea, I’d like to see it, because I’m stuck.

[code]- (void)setThumbnailDataFromImage:(UIImage *)image
// Release the old thumbnail and data
[thumbnailData release];
[thumbnail release];

// Create an empty image of size 70x70, maintaining the aspect ratio

float w = image.size.width;
float h = image.size.height;

if (w>70.0) {
	h = (70*h)/w;
	w = 70;
} else if (h>70) {
	w = (70*w)/h;
	h = 70;

CGRect imageRect = CGRectMake(0, 0, w, h);

// Render the big image onto the image context
[image drawInRect:imageRect];

// After here, method continues as usual

As I’m using an iPad, I am limited to photos I’ve imported into the device. Not a big issue, however I’ve noticed that this way of implementation works best for standard-sized, landscape-oriented images, so, once again, if anyone has a better idea, I’m all eyes.