Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is PNG preferred over JPEG for all image files on iOS?

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?

like image 909
Zebs Avatar asked Mar 29 '12 01:03

Zebs


1 Answers

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.

like image 129
Jack Humphries Avatar answered Sep 21 '22 14:09

Jack Humphries