1

I have following drawable with different sizes for mdpi, hdpi, xhdpi....

-rw-r--r--@ 1 xxx  yyy    31K Apr 16 14:19 myImage.9.png
-rw-r--r--@ 1 xxx  yyy    63K Apr 16 14:19 myImage.9.png
-rw-r--r--@ 1 xxx  yyy    95K Apr 16 14:19 myImage.9.png
-rw-r--r--@ 1 xxx  yyy   196K Apr 16 14:19 myImage.9.png
-rw-r--r--@ 1 xxx  yyy   307K Apr 16 14:19 myImage.9.png

I use it as follows

    <ImageView
        android:paddingLeft="10dp"
        android:paddingRight="0dp"
        android:layout_centerVertical="true"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:scaleType="fitCenter"
        android:src="@drawable/myImage" />

My app at this point takes 20MB

If I make a change android:src="@null"

My app at this point takes 10MB

Why does the drawable takes so much memory where actual size is lot less??

GJain
  • 5,025
  • 6
  • 48
  • 82

1 Answers1

2

It depends on your screen resolution, think as how many points on the screen. Each point has colour information or depth (depends on Android version >= 2.3 loads bitmaps with 32 bits by default).

Even with low resolution picture, OS scales it (add points) so it can be viewed on a large screen.

So you get X * Y * colour depth.

As usual here we have trade off: size on the disk (real resolution and colour depth), cpu time (scaling).

For example you have phone with screen resolution 200*100 = 20_000 points. If you want to draw something on the whole screen, you have to light all 20_000 points and each point has colour information (the simple case RGB). As a result 20_000 points * depth (in our case 32bit) = 640_000 bits.

Check graphics architecture internals.

Maxim G
  • 1,479
  • 1
  • 15
  • 23
  • I dont quite understand it...could you please give a small example. I now put all drawbles at hdpi size into nodpi and use nodpi in code....do you think thats ok across devices?? – GJain May 10 '16 at 07:54
  • Larger screen density more memory you need. – Maxim G May 10 '16 at 08:25