Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Bitmap size is bigger in memory than on disk in Android?

I have a 2448x3264 image on my SD card that consumes 1,667,072 bytes but when I load it as a Bitmap and calculate its size using getRowBytes()*getHeight() I end up with 15,980,544 bytes.

Why does this happen and how can I calculate the actual size of the file?

like image 513
Saqib Avatar asked Jul 12 '12 21:07

Saqib


People also ask

Why is a bitmap image so large in file size?

BMP stands for bitmap, a raster-based file type designed in the early days of computer graphics to display images independently from devices. Because BMP files are information-rich, they tend to have large file sizes.

How is a bitmap stored in memory?

The bitmap is stored in its original compressed form to save memory (PNG, JPEG, etc) The bitmap is stored in 24-bpp format so its slower to access than a 32-bpp image. The bitmap is not stored in a packed memory array and is fragmented so can't be read/written fast.

What two factors affect the size of a bitmap?

The two main factors which affect the quality of a bitmap picture are and colour depth. The resolution is the number of pixels per , measured in dots per inch () or pixels per inch (ppi). The higher the resolution the better the of the picture. A picture with a low resolution will when the picture is enlarged.

How do you handle bitmaps in Android as it takes too much memory?

If you're displaying large amounts of bitmap data in your app, you're likely to run into OutOfMemoryError errors. The recycle() method allows an app to reclaim memory as soon as possible. Caution: You should use recycle() only when you are sure that the bitmap is no longer being used.


1 Answers

That is because the image is compressed when it is on disk (stored in a JPG, PNG, or similar format). Once you load the image into memory, it is no longer compressed and takes up as much memory as is necessary for all the pixels (typically width * height * 4 for RGBA_8888, or width * height * 2 for RGB_565).

like image 107
devunwired Avatar answered Oct 07 '22 16:10

devunwired