我有一個方法與透明度位圖替換特定的顏色與透明度
public Bitmap createTransparentBitmapFromBitmap(Bitmap bitmap,
int replaceThisColor) {
if (bitmap != null) {
int picw = bitmap.getWidth();
int pich = bitmap.getHeight();
int[] pix = new int[picw * pich];
bitmap.getPixels(pix, 0, picw, 0, 0, picw, pich);
int sr = (replaceThisColor >> 16) & 0xff;
int sg = (replaceThisColor >> 8) & 0xff;
int sb = replaceThisColor & 0xff;
for (int y = 0; y < pich; y++) {
for (int x = 0; x < picw; x++) {
int index = y * picw + x;
/* int r = (pix[index] >> 16) & 0xff;
int g = (pix[index] >> 8) & 0xff;
int b = pix[index] & 0xff;*/
if (pix[index] == replaceThisColor) {
if(x<topLeftHole.x) topLeftHole.x = x;
if(y<topLeftHole.y) topLeftHole.y = y;
if(x>bottomRightHole.x) bottomRightHole.x = x;
if(y>bottomRightHole.y)bottomRightHole.y = y;
pix[index] = Color.TRANSPARENT;
} else {
//break;
}
}
}
Bitmap bm = Bitmap.createBitmap(pix, picw, pich,
Bitmap.Config.ARGB_8888);
return bm;
}
return null;
}
其所謂像這樣
backgroundBitmap = createTransparentBitmapFromBitmap(backgroundBitmap , Color.argb(255,255,255, 0));
更換一種顏色的像素相同的顏色我有一個PNG文件,我想要透明的洞。問題是它只取代部分顏色不是全部。 查看截圖https://docs.google.com/document/d/18aH43sFmsuuRu0QNfMTD1zek8sqWwH_pTauFofDZeIw/edit
鏈接給我一個未命名的文檔。你確定你已經建立了共享和不正確的? –
我剛剛編輯它,現在應該是好的 – tsukimi