开发者

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, 开发者_如何学JAVAthe quality is very poor. Does anyone know how this can be done without losing image quality?


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/


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜