Jonathan Brown
Jonathan Brown

Reputation: 3822

Resizing UIImage and saving

I am trying to figure out how I can shrink and save a UIImage, read it back in later, and then convert back to the original size without losing quality. I have managed to do the resizing and saving, but the problem is that if I save it smaller, when I read it back in and expand it, the quality is very poor. Does anyone know how this can be done without losing image quality?

Upvotes: 0

Views: 1351

Answers (2)

James Bush
James Bush

Reputation: 1525

Although you cannot upsize a downsized image, you can display a downsized one while retaining a reference to the original image (which you can save):

UIImage *image = [UIImage imageNamed:@"myImage"];
[image drawInRect: destinationRect];
UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);

The destinationRect will be sized according to the dimensions of the downsized version.

Upvotes: 0

hundreth
hundreth

Reputation: 841

You can't downsize the image and then bring it back without losing quality. You can't make something out of nothing, once you lose the data you lose the data.

You will need to save two versions of the image, one large and one small. This is a very typical scenario when dealing with thumbnails.

Check out the following site which provides categories for resizing images as well as several other really cool stuff:

http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

Upvotes: 4

Related Questions