如何绘制一个具有给定颜色透明度的位图?例如,我希望所有白色像素都是透明的。
你需要为传递给位图的绘图设置 Alpha 值。
http://developer.android.com/reference/android/graphics/Paint.html#setAlpha%28int%29
取值范围为0-255。
编辑:
Paint p = new Paint();
//Set Blue Color
p.setColor(Color.WHITE);
//Set transparency roughly at 50%
p.setAlpha(125);
你需要检查图像的每一个像素并更改其颜色。 你可以在这个帖子中找到答案。
//Set transparent paint - you need all of these three
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT));
paint.setColor(Color.TRANSPARENT);
// Do you wanna soften?
// Set paint transparency:
// 0 = transparent ink, no visible effect
// 255 = full ink, hole in the bitmap
p.setAlpha(192);
// Do you want some blur?
// Set blur radius in pixel
paint.setMaskFilter(new BlurMaskFilter(10, Blur.NORMAL));