Android Baidu map bitmap transparent picture background turns black

Phenomenon:

When a png image with a transparent background is rendered, it turns out to be black.

 reason:

In order to save memory resources, the image is compressed using

bitmap.compress(Bitmap.CompressFormat format, int quality, OutputStream stream) method, the specific settings are as follows
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, stream);

The bitmap is set to Bitmap.CompressFormat.JPEG format. JPEG does not have a transparent channel and is rendered as black by default. Therefore, the format needs to be set to PNG format, that is:

bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream);

Effect:

Solve the problem 

Guess you like

Origin blog.csdn.net/qq_55888300/article/details/132235806