Png loses transparency in Android (if all pixels are opaque)

I have an application with two views - one above the other. In the top one, I use the bitmap loaded from the PNG resource (argb_8888). I play its alpha channel to make some parts of it disappear, so the lower one becomes visible. If the source image has at least one transparent pixel, everything is normal. But if the source PNG has no transparent pixels, Changing alpha to 0 will make pixel I black instead of transparent

Is there any idea to solve it? Anything:

aaptOptions {
    cruncherEnabled = false
}

But another option?

At present, I modified the source image before compiling to make a small area "translucent", but I want to avoid this situation

resolvent:

OK. I finally understand

I had to add a line. Instead:

mBitmap = BitmapFactory.decodeResource(getResources(), getResourceID()).copy(Bitmap.Config.ARGB_8888, true);

I'm using:

mBitmap = BitmapFactory.decodeResource(getResources(), getResourceID()).copy(Bitmap.Config.ARGB_8888, true);
mBitmap.setHasAlpha(true);

And there is no need to add transparent pixels to the source image!

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
分享
二维码
< <上一篇
下一篇>>