Something you don’t know about Android bitmap

This article shares the details of Android bitmap for your reference. The specific contents are as follows

1. Several ways of computer graphics

1) BMP: almost no compression, occupying a large space. 2) JPG: compressing adjacent pixels on the basis of BMP, occupying a smaller space than BMP. 3) PNG: further compression on the basis of JPG, occupying a smaller space

This is a brief introduction to the three formats. Just know what's going on. PNG images are generally used in Android because they take up a small space

2. The size of the drawing

Size of graphics = total pixels of the picture * size of each pixel total pixels of the picture = length of the picture * height of the picture

You can see that there are some options when saving a picture. Take a look at several monochrome bitmaps: each pixel can represent up to 2 colors, which only needs to be represented by binary bits with a length of 1, so each pixel accounts for 1 / 8byte. 16 color bitmaps: each pixel can represent up to 16 colors, so only binary representations with a length of 4 are required, Therefore, each pixel accounts for 1 / 2byte 256 color bitmap: each pixel can represent 256 colors at most, so it only needs the secondary bit representation with a length of 8. Therefore, each pixel accounts for 1byte 24 bit bitmap: that is, RGB three primary color bitmap accounts for 3 bytes per pixel.

3. Why Android failed to load the big picture

After knowing the above knowledge, let's study the bitmap information in Android. ARGB is used to represent the color in Android, so each pixel will occupy 4 bytes. When the original image is loaded with bitmapfactory, it will appear when the width and height of the image are much larger than that of the mobile phone

That is, the memory is out of bounds, but the size of the picture does not exceed the memory allocated to each application by the system. Therefore, it can be determined that the image calculation method when loading the original image is calculated according to the above formula.

4. Method of loading large drawing

After knowing the reason for the failure of loading the large image, the solution to outofmemoryerror is obvious. The right thing is to zoom. Let's take a look at the following steps: 1) obtain the width and height of the mobile phone 2) obtain the width and height of the picture 3) calculate the zoom ratio 4) display the picture according to the zoom ratio

5. Bitmap modify picture

When looking at a situation, use bitmapfactory After a picture is decodexxx decoded, the picture needs to be modified, such as:

It is found that an error is reported after pushing to the mobile phone, because the original image cannot be modified. So what happens when you need to modify the picture? By the way, you can manipulate the copy of the original drawing, which can be modified. The steps to create a copy of the original drawing are as follows:

1) Create a template 2) create a canvas with the original drawing as the template 3) create a brush 4) start copying the original drawing

So far, I have found some small details in my work. Other methods of operating bitmaps should be well known, so I won't teach others.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>