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
There are many popular videos on Douyin with very...
【HuiSpeaks English】One-stop English listening and...
Last month, the Ministry of Industry and Informat...
On September 22, at the "2017 China OTT Larg...
[[419088]] On August 23, Ant Group’s consumer rig...
It is important to make users feel that the servi...
Users who have upgraded to iOS 14 will definitely...
Jing Wei's "Short Video Camera Lighting ...
The more exaggerated, the more explosive? Totally...
As network technology becomes increasingly mature...
Vipshop has developed rapidly. It was listed on t...
There are many channels for APP promotion . Today...
New employees in the workplace often encounter a ...
The European Union has issued new guidelines to i...
The article combines the author's own experie...