尝试
此
private Drawable fillBitmap(Bitmap bitimg1, int r, int g, int b) {
Bitmap bitimg = bitimg1.copy(bitimg1.getConfig(), true);
int a = transperentframe;
Drawable dr = null;
for (int x = 0; x < bitimg.getWidth(); x++) {
for (int y = 0; y < bitimg.getHeight(); y++) {
int pixelColor = bitimg.getPixel(x, y);
int A = Color.alpha(pixelColor);
bitimg.setPixel(x, y, Color.argb(A, r, g, b));
}
}
Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitimg,
framewidth + 10, frameheight, true);
dr = new BitmapDrawable(getResources(), resizedBitmap);
return dr;
}
通过使用该代码i的非透明区域填充颜色成功离开了透明区域,因为它是。
ü还可以检查这样的:
if(canvasBitmap.getPixel(x, y) == Color.TRANSPARENT)
你可以比较任意颜色Color.BLUE任何根据您的需要应用其他方法。
谢谢你的回答@詹姆斯,但我真的不能真正把它工作。这是我在我的onDraw方法中的代码: 位图bitmap = bit.copy(Bitmap.Config.ARGB_8888,true); \t \t Paint paint = new Paint(); \t \t paint.setARGB(255,0,0,0); // ARGB为颜色,在本例中为白色 \t \t int removeColor = paint.getColor(); \t \t paint.setARGB(255,255,0,0); (新的AvoidXfermode(removeColor,0,AvoidXfermode.Mode.TARGET)); \t \t canvas.drawBitmap(bitmap,0,0,null); \t \t canvas.drawPaint(paint); 我得到的只是一个红色的屏幕。 – RadicalMonkey 2013-03-19 13:21:59
您需要修改'paint.setARGB(255,0,0,0)'行以匹配要覆盖的颜色的ARGB值。 – 2013-03-19 17:25:28