I was originally working on TV applications, but because the company was going to release a mobile phone and was short of staff, they assigned me to support it. Who says I am Lei Feng? One of the functions I worked on was to process the application icons in the mobile phone. The processing was nothing more than beautification, re-combination and cropping with the baseboard, which used a lot of knowledge about Bitmap. I had always wanted to write some blogs about Bitmap, and this happened to be an opportunity, so the series of blogs about Bitmap was born. In this series, I will publish some knowledge I learned about Bitmap for your reference and communication. In mobile phones, pictures generally refer to Bitmap pictures. Why do we say Bitmap? Because when developing applications, we will use some pictures to express UI, and users also like to look at pictures. It is too slow and not intuitive to get information by looking at text. If the art design is good, you can basically know what you want to express by looking at the pictures without looking at the text content. For example, all shopping websites will edit a lot of pictures of products to present to users. This shows that pictures are common and important in applications. As long as we talk about pictures, we can't leave the topic of how to avoid OOM, because OOM is easy to appear when processing many pictures, so learning picture processing is particularly important. Let us learn the relevant knowledge of pictures step by step. Memory usage calculation of Bitmap images:
What you need to pay attention to when using pictures: 1. Problems with the Android system itself. The Android system allocates a certain amount of memory space to each application. The amount depends on the manufacturer and model. The value can be obtained through the Runtime class. Runtime.getRuntime() gets the instance, and then the maxMemory() method is used to get the maximum memory that the system can allocate to the APP. totalMemory() gets the size of the memory heap space currently allocated to the APP, and freeMemory() gets the current available memory. When it is exhausted, it will automatically expand, but it will not exceed maxMemory. The figure below shows the minimum memory allocated at different resolutions and different dpis provided by the Google official website; 2. How big a photo is needed. In fact, many pictures do not need to be completely loaded into the memory when they are displayed on the phone. For example, if I took a photo with my phone camera that is 4208*3120, it will take up 52M of memory when loaded into the memory. This is terrible. Two photos will almost use up your app's memory. In general, you need to process the pictures you need to load. This processing mainly reduces the size of the picture and reduces the resolution. For example, if your control display is 100*100 in size, you need to reduce the picture to 100*100. |
>>: Apple, you hurt me deeply, and you won't let me speak
On January 28, 2022, the State Council Informatio...
Children are also using generative AI, but they o...
After the policy dividends were withdrawn, due to...
In January this year, I was invited by Apple to s...
The development of the Internet has a history of ...
In the past week, the biggest event in the televi...
There is a proverb in English, "There is no ...
Over the years, mobile phones have increasingly t...
As a bidder, setting up an account is a common th...
Because I am not familiar with Facebook's adv...
Once the product is made, the big challenge is ho...
According to the latest news from the xda forum, ...
When it comes to understanding traffic , many peo...
The China Academy of Information and Communicatio...
gossip "Colored glass cups are poisonous and...