views:

308

answers:

2

Hi All, 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.

A: 

ImageView has a setAlpha method which takes an integer between 0 and 255. I don't know which is transparent and which is opaque but it shouldn't take a long time to try :P

molnarm
Hi, thanks for the reply. setAlpha() will make entire image transparent. I want a behaviour like, where user touches or moves his finger on image, that portion should turn to transparent.
Andhravaala
+2  A: 

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#

Mathias Lin