天天看點

Android中擦除Bitmap中的某一塊

以前要截取Bitmap中的圖檔使用的一塊塊的拼接,雖然可以實作,但是效率很低。想了很久,無意中看到網上的對BITMAP圖檔的RGB資訊進行修改,然後想出了這個辦法,感覺用起來還是挺舒服。很多出錯處理都沒有寫,隻實作基本功能啊

public static Bitmap setTransparentAreaForBitmap(Bitmap b, 
        int width, int height, int paddingleft, int paddingtop) {
    if (b == null) {
        return null;
    }
    int []pix = new int[width * height];
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            int index = j * width + i;
            pix[index] = 0x00000000;
        }
    }
    b.setPixels(pix, 0, width, paddingleft, paddingtop, width, height);
    return b;
}