DLee
DLee

Reputation: 300

Android: Purpose of using images with different pixel density?

I know using images with different DPI is a fairly common practice in Android. But I don't really see the purpose of it, why can't we just use a ultra huge image and then scale it in the program? I know we probably need to do extra calculation if we don't images in different DPI, but besides that, is there's any other reason?

Upvotes: 1

Views: 519

Answers (3)

Kevin Coppock
Kevin Coppock

Reputation: 134714

Tim and a.d. have the correct reasoning for you. Here's a visual example if you'd like to see a comparison between something rescaled or drawn at the correct size. Effects are always more noticeable if there are very small details.

enter image description here enter image description here enter image description here

The first is a large 200x200 (we'll call it xhdpi), and the second is simply the same image resampled for mdpi (75x75). The third is redesigned to the same specs but starting at 75x75. As you can see, the text on the second is significantly blurred, and there are some artifacts along the edges of the shapes where rescaled.

Upvotes: 6

FoamyGuy
FoamyGuy

Reputation: 46856

By providing images that are already rendered to appropriate sizes for each of the major classes of screen density you avoid the need to explicitly do the scaling within your code, which will make for "cleaner" code.

You also avoid the performance drain that would result from each and every image being shown having to be scaled, depending on exactly how much scaling your app would have to do it could be a significant boost to performance to not do these operations "on the fly" as the Views are being shown to users.

And lastly providing appropriately rendered images for each size will ensure that your resources look nicer. The system scaling is not perfect and will errode the "clearness" of your images if it has to scale them at all. If it has to scale them significantly this will be noticeable to the user.

Upvotes: 1

android developer
android developer

Reputation: 116070

you get optimized images for the density of the screen. if you leave it all for xhdpi , you must know that some important pixels might be gone in the process , because you didn't pay attention to that .

if you don't care about speed and accuracy , and you think that people won't notice important pixels being missing , it's ok to use this approach .

not only that , but if you scale the images yourself (using weights, for example) , you don't need to put them in dpi folders at all - you can put them in drawable-nodpi folder.

Upvotes: 2

Related Questions