Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Overlaid image transparent on touch in Android?

I need help on making the touched areas of bitmap image transparent(seems like erasing) while I am moving my finger on that image.

I am having a PNG file with Alpha channel in it. I want to turn the touched pixels to transparent so that, the user can feel that he is actually erasing it.

For this I am using frame layout to load 2 layers. Down layer is for content and upper layer is an Imageview for erasing. I need erase the upper layer when user touch and move his finger on it.

I am not getting how to make it transparent. can anyone please help me in this. If possible please direct me to any sample code, as I am very new to this image processing.

Thanks in advance.

like image 560
Andhravaala Avatar asked Jun 11 '10 08:06

Andhravaala


People also ask

How do I make the background of an image transparent?

Click Picture Tools > Recolor > Set Transparent Color.


1 Answers

You need to set the PorterDuff mode on a Paint object:

mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)) 

and draw with Color.TRANSPARENT

Also see this thread in the Android developer group: http://groups.google.com/group/android-developers/browse_thread/thread/5b0a498664b17aa0/de4aab6fb7e97e38?lnk=gst&q=erase+transparent#

like image 174
Mathias Conradt Avatar answered Oct 31 '22 01:10

Mathias Conradt