8

Xcode optimizes png images so they are loaded faster, but is this also recommended for other image resources that are not for buttons and UI (Photos for example)?

Or is it a standard to have UI images as png and "photos" as JPEG?

What is the best practice here?

Zebs
  • 5,378
  • 2
  • 35
  • 49
  • possible duplicate of [When to use PNG or JPG in iPhone development?](http://stackoverflow.com/questions/3929281/when-to-use-png-or-jpg-in-iphone-development) – Rob Napier Mar 29 '12 at 02:14
  • PNGs can load even faster if you *don't* let Xcode touch them: http://imageoptim.com/xcode.html – Kornel May 25 '12 at 19:13

2 Answers2

10

The best practice is to use PNG files as often as possible when using images within your app. iOS and Xcode load and display PNGs quickest as opposed to any other type of format. If given a choice, go with PNG.

When you use any other file type (or if you load a non-optimized PNG files), your iPhone has to do the byte-swapping and alpha premultiplication at load-time (and possibly re-do the alpha multiplication at display time). Your application basically has to do the same processing that Xcode does, but it's doing it at run-time instead of at build-time. This is going to cost you both in terms of processor cycles and memory overhead. One of the reasons why Mobile Safari is the biggest memory hog of the built-in iPhone applications is because the images it has to load in order to display web-pages are all non-optimized images, mostly JPEGs. Since JPEG is a compressed format, it has the added extra step of having to decompress the image into memory before it can do the premultiplication and byte-swapping.

Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
  • 4
    the claim that PNG are faster than JPG is not supported by tests http://www.cocoanetics.com/2012/09/iphone-5-image-decompression-benchmarked/ . Rather, seems to me PNG are good choice for small elements/images or if alpha/transparency present - and JPG is for everything else – Nas Banov Feb 09 '15 at 20:17
0

For what it's worth, Apple recommends using the PNG format for images. There's a lot more information on this topic in this Apple documentation.

Dhruv Saraswat
  • 858
  • 9
  • 13