Android image footprint Full analysis _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.