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
Every time I organize an event, I have to write a...
Torpedoes are an indispensable and important weap...
Whether it is an old brand that has quickly becom...
The so-called pendulum theory, It is said that ma...
Predicting the launch of new products is like for...
This paper mainly analyzes the basic attributes, ...
When it comes to the advertisements that are most...
Summer is here, and it is the season for barbecue...
People in every industry will get older. Do they ...
Since 2013, HTC has eliminated the complicated na...
What promotional information can be found on Baid...
It was somewhat difficult to adapt to the transit...
Open the APP on your phone, no matter which e-com...
The field of protein design has reached another m...