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

2

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?

Palstave answered 29/3, 2012 at 1:57 Comment(2)
possible duplicate of When to use PNG or JPG in iPhone development?Daisy
PNGs can load even faster if you don't let Xcode touch them: imageoptim.com/xcode.htmlAhvenanmaa
C
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.

Chuppah answered 29/3, 2012 at 2:13 Comment(1)
the claim that PNG are faster than JPG is not supported by tests cocoanetics.com/2012/09/… . Rather, seems to me PNG are good choice for small elements/images or if alpha/transparency present - and JPG is for everything elseDali
T
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.

Taskmaster answered 2/12, 2022 at 5:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.