0

I have made an iphone app in which i download the images via FTP & saved in document Directory. These Images are of high memory size (approx. 2-3 MB).

Then I display these images in UITableview with many rows & due to these Images the allocation memory is too big & that's why app crashes.

So, I need to reduce the memory size of these images.

How can I do this?

Thanks,

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Rohan
  • 2,939
  • 5
  • 36
  • 65
  • possible duplicate of [The simplest way to resize an UIImage?](http://stackoverflow.com/questions/2658738/the-simplest-way-to-resize-an-uiimage) – Wain Jul 31 '13 at 10:50
  • 1
    @iAmbitious, in what way is resizing images bad practice? – Wain Jul 31 '13 at 10:54

1 Answers1

2

Make thumbnail of the images before you add them to the UITableView. In this way the size of the images would reduce drastically. Use the following code on the UIImages you are picking from the document directory .

UIImage *originalImage = ...;
CGSize destinationSize = ...;
UIGraphicsBeginImageContext(destinationSize);
[originalImage drawInRect:CGRectMake(0,0,destinationSize.width,destinationSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Also have a look at the following links :-

Thumbnail view of images

http://www.icab.de/blog/2010/10/01/scaling-images-and-creating-thumbnails-from-uiviews/

https://gist.github.com/djbriane/160791

Community
  • 1
  • 1
IronManGill
  • 7,222
  • 2
  • 31
  • 52
  • Thumbnails are definitely the way to go. Also consider offering thumbnails *from the server*, if you want to avoid creating them on the device. It all depends on the situation. You could even download *only* the thumbnails, and then when the user wants to view an image full size, download that. This will save users lots of bandwidth, considering you're avoiding several 2-3 MB images. – Timo Jul 31 '13 at 11:31