R – What’s the fastest way to load big image on iPhone

iphonememoryperformanceuiimage

Should I use UIImage or CGImage ? Png or Jpg ?
I've read the doc and tried different things but did not notice significant improvement.
Loading an image can take 1 good second which seems slow

Best Answer

UIImage is just an ObjC wrapper of CGImage, so they're the same.

From the SDK doc:

You should avoid creating UIImage objects that are greater than 1024 x 1024 in size. Besides the large amount of memory such an image would consume, you may run into problems when using the image as a texture in OpenGL ES or when drawing the image to a view or layer. This size restriction does not apply if you are performing code-based manipulations, such as resizing an image larger than 1024 x 1024 pixels by drawing it to a bitmap-backed graphics context. In fact, you may need to resize an image in this manner (or break it into several smaller images) in order to draw it to one of your views.

If you have a huge image, you could try to use a UIWebView to reduce memory consumption.


The time to load an image has 2 parts: the time to decompress the image (relevant to choosing JPG or PNG) and the time to render the image.

For decompressing, I'd suggest you profile the simple statement

[UIImage imageWithContentsOfFile:@"/path/to/your/image.jpg"];