Reputation: 5093
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??
Upvotes: 1
Views: 247
Reputation: 1489
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.
Upvotes: 2