Trouble making parts of a bitmap transparent

Go To


I'm developing an android app where i need to capture text and save it as a transparent image. Capturing the text has been done but making a transparent png file is where i'm stuck as i'm not familiar with image pixel manipulation at all. Here's what I have so far... i first create a blank bitmap and fill it with a white background, then i set the paint's transparency to 0 (full transparency) and then draw the source bitmap into the destination bitmap using the XOR modes.. but when i run the app all i see is a blank white image. i'll be glad if someone points out what i'm doing wrong and how to fix it. Thanks in advance.

b = Bitmap.createBitmap(tw, th,Bitmap.Config.ARGB_8888); 
Canvas canvas = new Canvas(b);
Rect dest = new Rect(0,0,b.getWidth(),b.getHeight());               
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

canvas.drawRect(0, 0, b.getWidth(), b.getHeight(), paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
2012-04-04 03:01
by Cool Dude


Have you looked at : How to change a bitmap's opacity? Seems like


won't do anything as you need to set the alpha channel to something greater than 0...

2012-04-04 03:14
by roboto1986
From what i understand, a value of 0 will give full transparency while a value of 255 will give full opacity - Cool Dude 2012-04-04 03:29




The first parameter is the alpha. Set it to 0 for complete transparency.

2012-04-04 03:21
by zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz