android - How to make some part of bitmap transparent? -
i have bitmap http://i.hizliresim.com/gyr6jv.jpg on file system. need make black part of image transparent , obtain circular bitmap. transparent method used:
public static bitmap maketransparent(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 y = 0; y < pich; y++) { // left right (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) { pix[index] = color.transparent; } else { break; } } // right left (int x = picw - 1; x >= 0; 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) { pix[index] = color.transparent; } else { break; } } } bitmap bm = bitmap.createbitmap(pix, picw, pich, bitmap.config.argb_8888); return bm; } return null; } thanks.
hey if want create circle image can use https://github.com/hdodenhof/circleimageview
edit: solution first draw transparent image form ressource draw image in disc (and disc)
Comments
Post a Comment