graphics - Circle crop image with transparent background - Android -
i'm trying described here "i want crop circular region bitmap. pixels outside circle should transparent."
i trying what's in post of them don't offer transparent background, circle image, tried below , didn't work, ideas?
public bitmap getcroppedcircleimage(bitmap bmp, view view) { bitmap bitmap = getcroppedimage(bmp, view); bitmap output = bitmap.createbitmap(bitmap.getwidth(), bitmap.getheight(), bitmap.config.argb_8888); canvas canvas = new canvas(output); final int color = 0xff227722; final paint paint = new paint(); final rect rect = new rect(0, 0, bitmap.getwidth(), bitmap.getheight()); paint.setantialias(true); canvas.drawargb(0, 0, 0, 0); paint.setcolor(color); //canvas.drawroundrect(rectf, roundpx, roundpx, paint); canvas.drawcircle(bitmap.getwidth() / 2, bitmap.getheight() / 2, bitmap.getwidth() / 2, paint); paint.setxfermode(new porterduffxfermode(porterduff.mode.src_in)); canvas.drawbitmap(bitmap, rect, rect, paint); paint paint1 = new paint(); paint1.setxfermode(new porterduffxfermode(porterduff.mode.clear)); rect recttransparent=new rect(0, 0, bitmap.getwidth(), bitmap.getheight()); canvas.drawrect(recttransparent,paint1); paint.setxfermode(new porterduffxfermode(porterduff.mode.src)); canvas.drawbitmap(bitmap, rect, rect, paint); //bitmap _bmp = bitmap.createscaledbitmap(output, 60, 60, false); //return _bmp; outputstream stream = null; try { stream = new fileoutputstream("/sdcard/test.png"); } catch (filenotfoundexception e) { e.printstacktrace(); } bitmap.compress(bitmap.compressformat.png, 100, stream); try { stream.close(); } catch (ioexception e) { e.printstacktrace(); } return output; }
you can use library achieve goal
Comments
Post a Comment