I am developing an android application which displays an image as background. I have read the documentation and it says that Mdpi
should be the base line and all other dpi's should be relative to it. But I am not able to decide what should be the resolution of background image in pixels I should for all the dpi's?
Any suggestion?

- 1,539
- 1
- 18
- 45
-
Is it a full size image? or a tile? or a centered picture? – Phantômaxx Jul 27 '14 at 17:37
-
@FrankN.Stein Its a full size image. Currently i have it in 1080x1920 reso – Abhishek Batra Jul 27 '14 at 17:50
-
A 1080x1920 image is going into the `drawable-xxhdpi` folder. The corresponding `mdpi` image is 360x640px (xxhdpi is a 3.0x scale factor). You can use `drawable-nodpi` to avoid density-based scaling, but because phones with smaller screens tend to have less memory as well, I recommend providing several smaller images, at least mdpi and hdpi. – Barend Jul 27 '14 at 18:04
-
See also [density scale factors](http://stackoverflow.com/a/18656286/49489) and [screen fragmentation myth](http://rustyshelf.org/2014/07/08/the-android-screen-fragmentation-myth/). – Barend Jul 27 '14 at 18:09
-
Mind that providing a bunch (one per each supported resolution, possibly in two flavours - portrait and landscape) of full sized images will make your app consistently grow in size. – Phantômaxx Jul 27 '14 at 18:15
-
I recommend you scale bitmaps, otherwise if you have too many images loaded you can have an OutOfMemoryError. http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – ChallengeAccepted Jul 27 '14 at 21:21
1 Answers
The best approach depends but, to save space and retain resolution at all densities, include only a single image in your app. When your activities load, use a scaled load based on the the DisplayMetrics of the device. If you aren't worried about resolution, then scaling up from MPDI is fine (but I'm pretty sure you're asking because resolution at the higher densities is a concern, and based on your background image size).
The advice for "starting" with MDPI has to do with the numeric scaling that is needed and being able to conceptualize it. In other words, it is easiest to "think" about how scaling works on Android when you start with MDPI. After that, your use-case is far more important.
There are many examples for scaling images based on your needs. Do not forget to use caching whenever possible, if your application loads several.
Another thing to consider is the extended heap memory, if you encounter OOME because of iamge handling issues.

- 10,172
- 1
- 27
- 36
-
+1 Because THIS is the proper approach to handle images. I also suggest you view this documentation on loading large bitmaps efficiently: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – ChallengeAccepted Jul 27 '14 at 21:18