嘗試
此
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