2

I am loading a UIImage of size 2480 × 3508 into UIImageView using UIViewContentModeScaleAspectFit. I am getting memory warning while loading this image. And after i loaded a few images of this size in this UIImageView the application crashes. Is there any method to solve this.

Priyanka V
  • 834
  • 2
  • 12
  • 34

3 Answers3

3

Solution to this problem consists of either loading scaled version of the image (*1) or you have option to display it in full resolution with help of CATiledLayer(*2).

  1. [UIImage imageWithCGImage:scale:orientation:];
  2. CATiledLayer example

Addendum: If your image source is Photo Library, ALASSet provides already scaled image to full screen and full resolution image. You can use combination of both with CATiledLayer. Full screen image is added to layer beneath the CATiledLayer to serve as placeholder while you're waiting for tiles in CATiledLayer to load.

TheBlack
  • 1,245
  • 1
  • 8
  • 12
1

Well, according to the documentation :

You should avoid creating UIImage objects that are greater than 1024 x 1024 in size.

Reduce your image then load it in your ImageView, there are plenty of libraries to do this, here is one :

https://github.com/Nyx0uf/NYXImagesUtilities

Nyx0uf
  • 4,609
  • 1
  • 25
  • 26
  • 2
    yes this is true, you can calculate the memory usage: 2480 × 3508 * 4 = 34799360 bytes of memory. – rckoenes May 24 '11 at 12:53
  • I am using a scrollview and uiimageview is a subview of uiscrollview. So if i am reducing the image size the image become blurred while zooming – Priyanka V May 24 '11 at 13:10
  • In this case you should take a look at CATiledLayer : http://www.olivetoast.com/blog/2009/08/simple-uiscrollview-catiledlayer-pdf-example/ – Nyx0uf May 24 '11 at 13:11
  • k. This is a good option. After the use of this huge image i am setting the UIImage.image property to nil. Don't this release the memory used for loading the previous large image. – Priyanka V May 24 '11 at 13:15
0

You can use this for scaling The method is described simply in the following link:

How to scale a UIImageView proportionally?

Community
  • 1
  • 1
SriPriya
  • 1,240
  • 15
  • 22