Once a friend asked me a question, a 512*512 150KB png format picture and a 512*512 100KB compression ratio is 8 jpg format picture, loaded into memory, that is, loaded into a bitmap, which occupies a large memory? This question seems to be a little difficult to answer, the test will know.
Well, I've got three pictures on request,
1.512*512px, 114KB, PNG
2.512*512px, 138KB, JPG, compression ratio 12
3.512*512px, 57KB, JPG, compression ratio 8
The next step is to write a demo, a bitmap load a different picture, and then use Bitmap.getrowbytes () * Bitmap.getheight (), and get the memory footprint of the picture. (Such a simple procedure will not be released shortcoming)
The numbers are actually the same. It's just 4MB, why 4MB? 512*512*4*2, so calculated, bitmap the default load using argb_8888, each pixel will occupy 4byte, because each pixel has two Chanel.
So, the size of the Android image is only related to the picture resolution (pixel) and color mode. Can refer to bitmap source code
Copy Code code as follows:
/**
* Each pixel are stored on 4 bytes. Each channel (RGB and Alpha
* for translucency) are stored with 8 bits of precision (256
* Possible values.)
*
* This configuration is very flexible and offers the best
* Quality. It should be used whenever possible.
*/
Today finally solved a knot in my heart, always thought that the larger the load of the picture will occupy more.
PS: is bitmap rendering using OpenGL? In Debug, you see the following information:
This is what I saw after I loaded a picture of a digital camera.