Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Bitmap size in memory

Tags:

android

bitmap

I am using a Nexus 5X emulator with a density of 420 dpi and screen size of 1080x1920 px. I load an original size bitmap into an ImageView. On disk, the bitmap's size is 1.3 MB and 1280x851 px. My ImageView dimensions are width: full screen, height: full screen. My image has a 32-bit color depth = 4 bytes per pixel. I calculated the expected size in memory as 1080x1920x4=8.29 MB.

When I run my code and load my image, it's size in memory is approximately 30MB. What is the reason for that and how can I adjust my calculations in order to get the right estimation? I am of course aware methods to load a downscaled image into a small container but I try to figure out how to calculate the size of the full image.

Thanks

like image 235
Ozzz Avatar asked Feb 07 '23 01:02

Ozzz


1 Answers

I calculated the expected size in memory as 1080x1920x4=8.29 MB.

The screen size does not matter here.

res/drawable/ is an old synonym for res/drawable-mdpi/. You are indicating that your image is designed for -mdpi devices (~160 dpi), and that it should be up-sampled for higher-density devices (and down-sampled for -ldpi devices).

A Nexus 5X is classified as an -xxhdpi device (~480 dpi). This means that each pixel of your original image should be mapped into 9 pixels in the up-sampled image (480 / 160 = 3 on each axis). 1280 x 851 = 1089280 pixels * 9 scaling factor * 4 bytes/pixel = 39214080 bytes = 37.4MB.

like image 142
CommonsWare Avatar answered Feb 13 '23 07:02

CommonsWare