1

I have a flags.png file that's 24480x160. I put this file in the "drawable" folder and loaded it into a bitmap on an emulator that's 420dpi (xhdpi). I generated a heap dump and checked the hprof. The bitmap drawable was occupying 8.7 MBs. The heap size was 72 MBs with 56 MBs allocated.

Doing the same exercise with the image in the xxxhdpi folder, the bitmap drawable remains the same size, but the heap size becomes 28 MBs with 17 MBs used.

I understand that "drawable" is considered to be mdpi and that Android will do some scaling when loading the image. It seems to be doing the same thing with hdpi and mdpi drawables on an xhdpi device as well. What I don't understand is what exactly happening that's resulting in the same 8.7 MB image but with different heap sizes. More specifically, if it's going to result in the same 8.7MB image, why scale in the first place and cause a large heap increase?

trincot
  • 317,000
  • 35
  • 244
  • 286
black
  • 781
  • 1
  • 7
  • 22
  • 1
    What gives you the idea that `drawable is considered to be mdpi` ? Link to the source please... only `drawable-mdpi` is considered to be mdpi. – Shark Mar 03 '16 at 09:19
  • drawable folder doesn't have into account the dpis, is intended for vector graphics (e.g. xml drawables). drawable-dpi is for raster bitmap images, which is the one you must use. Or use drawable-nodpi for your app no taking account on the density – webo80 Mar 03 '16 at 09:22
  • @Shark http://stackoverflow.com/questions/25568890/whats-differences-between-drawable-folder-and-drawable-hdpi-ldpi-mdpi-xhdpi – black Mar 03 '16 at 09:24
  • @webo80 You're missing the point. I did the same exercise with mdpi and hdpi. – black Mar 03 '16 at 09:25
  • @Shark `drawable` folder comes from ancient, dark ages where only `mdpi` density was supported, so, yes `drawable` == `drawable-mdpi` – pskink Mar 03 '16 at 10:05
  • @pskink I worked with android in those dark ages. Not android 1.0, but 2.0 (which we called B-droid) followed by Cupcake. it's a catch-all folder. `ResourceTypes.cpp` is in charge of picking the resources, the suffix does **not** repurpose the folder or give it different capabilities, it just helps the resource filter pick (and search thru) less resources. That being said, [here's an old question of mine asking about it](http://stackoverflow.com/questions/15087547/which-part-of-android-is-in-charge-of-picking-a-correct-resource-profile). That being said, I'm not picking sides here. – Shark Mar 03 '16 at 10:18
  • 1
    @Shark i think `nodpi` is a carch-all folder, see: https://commonsware.com/blog/2015/12/21/nodpi-anydpi-wtf.html – pskink Mar 03 '16 at 10:38

0 Answers0