This is the ninth day of my participation in the First Challenge 2022. For details: First Challenge 2022.

👉 About the author

As we all know, life is a long process of constantly overcoming difficulties and reflecting on progress. In this process, there will be a lot of questions and thoughts about life, so I decided to share my thoughts, experiences and stories to find resonance!!

Focus on Android/Unity and various game development tips, as well as various resource sharing (websites, tools, materials, source code, games, etc.)

Welcome to pay attention to the public account [Mr. Empty name] for more resources and communication!

👉 premise

Front small empty insist to write Android novice series, welcome to taste.

In the previous article we learned the layout optimization content, today we say picture optimization of the fast zai river’s lake!!

Pick up where we left off.

👉 Practice

Xiao Kong will take you through some concepts first

😜 Pictures exist in several forms

File form, that is, it exists on our disk, and that’s the size that we usually talk about the image size.

A Stream is a form of a Stream, like the pictures we see on the Web, all loaded in real time.

In Bitmap form, we usually refer to the size of the image in memory. The same image can take up different memory sizes on different devices if it is not processed properly.

Pixel density

Pixel density refers to the equipment or the number of pixels per inch, this and the inside of the resource file mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi are inseparable.

Color pattern

It is an algorithmic form that represents colors in the virtual world. It has multiple modes. In Android, we try to use them in Bitmap, and most of them are Config Settings, but what does each mean?

Alpha_8: Only bitmap transparency is stored, no color information, each pixel requires 1 byte of memory to store information.

ARGB_4444: Each 4 is meaningful, the 44 is ARGB, A(Alpha)4 bit accuracy, R(Red)4 bit accuracy, G(Green)4 bit accuracy, B (Blue)4 bit accuracy, that is, A pixel takes up two bytes of memory to store, and stores the transparency and color information of the image. It is a low-quality configuration.

ARGB_8888: This type of ARGB_4444 has the same principle, except that A,R,G, and B each have 8 bits of precision, so one pixel takes up 4 bytes of memory. More space is used, and more content can be displayed naturally. Therefore, the quality of the bitmap changed is better. Generally, this configuration is used by default and is also recommended.

RGB_565: after the above introduction, probably guessed 565 of whom he said, that’s right: R of five precision, G of six precision, B of five precision, there are 16 precision, it is the content of the two bytes. ARGB_8888 is A better choice than ARGB_8888 if you are demanding images with no transparency because there is no Alpha

😜 What is mass compression?

Mass compression is usually carried out without changing the size of the pixel quality compression, which may be difficult to distinguish with the naked eye, but the difference can be compared by magnifying and comparing. This compression changes the size of the image on the hard disk (that is, the File File) and has little effect on the size in memory.

The principle is: the main means of implementation is to process and assimilate the pixels around a pixel point through the algorithm, reduce the quality of the pixels or reduce, and then achieve the purpose of compression, but also change the size of the file. In addition, although PNG is lossless format, but still can be processed, but the effect is small, not ideal degree, are generally for JPG format picture processing.

Application scenario: Upload and download pictures.

😜 What is dimensional compression?

Image size compression refers to reducing the pixel value of unit size of an image according to a certain multiple. Originally, 1 unit has 6 pixels, but after compression, 1 unit has 2 pixels, which can not only change the size of the image in memory, but also change the size of the image in hard disk.

This is the easiest one to understand. Just like in the real world, the smaller the thing, the lighter the weight.

The idea is that by reducing the number of pixels per unit size, you literally reduce the number of pixels.

Application scenarios: Thumbnails of user profile pictures and chat process, etc.

👉 other

📢 author: Kom and Kom in Kom

📢 reprint instructions – be sure to specify the source: Zhim Granular’s personal home page – column – Nuggets (juejin. Cn)

📢 welcome to like 👍 collect 🌟 message 📝