in memory optimization, we found that in addition to resolving memory leaks, the only thing left was to reduce the actual memory footprint. In the app, most of the memory may be occupied by our pictures, so reduce the memory footprint of the image can bring a direct effect. This article simply introduces how much memory a picture occupies, let's assume that we have a picture of * * , the image occupies a space size assumption is 100KB.
How does the memory size of the picture relate to the size of the space?
The size of the footprint is not the size of the picture, some beginners may misunderstand. The footprint is a control that is occupied on disk, and the memory size is the amount of memory that is loaded into memory. Two units are just the same, the essence is not a concept.
How much memory does a picture occupy?
1. The image occupies the memory calculation formula: Picture Height * Picture width * One pixel memory size
2. So the above image occupies memory is:* * 4 byte = 1875KB = 1.83M
Why is 4byte in the above calculation formula?
4byte is related to the image encoding format, more details please visit
Http://www.cnblogs.com/popfisher/p/6770018.html
What is the memory effect of the directory in which the picture resides?
In Android, the image's storage directory and the screen density of the phone affect the final size of the picture, for example:
Assuming our images are placed in the xhdpi directory, the images in this article occupy the following memory sizes:
Device with a screen density of 2: * * 4byte = 1.83M
Device with a screen density of 3: * 1.5 * * * 1.5 * 4byte = 1.83 * 2.25M = 4.12M
So, to calculate the memory size of the picture, to consider the picture of the directory and device density, these two factors in fact, the effect is the height of the picture, Android will be pulled up and compression of the picture.
Summarize
1. The picture really occupies memory, memory optimization first consider the image memory consumption;
2. Be sure to avoid the use of large pictures, which is. 9 diagram is one of the most useful reasons;
3. The size of the image is proportional to the memory effect;
4. This article simply tells the reader how to calculate the memory size of the image.
5. How to reduce the image memory consumption of the method summary see http://www.cnblogs.com/popfisher/p/6770018.html
Android high-efficiency memory 1: How much memory a single picture occupies