Search code examples
androidimagepaint

Android Paint PorterDuff.Mode.CLEAR drawing black color on my view


I want to implement eraser for my painting app . I am able to erase with the following code

 paint.setColor(0x00000000);
 paint.setAlpha(0x00);

But after erasing when you start painting again it does not paint properly so any idea to erase paint please suggest.


Solution

  • Try the below code.

          paint.setAlpha(0xFF);//transperent color
          paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));//clear the draw
    

    Also have a look at the sample FingerPaint.java in the api demos under the folder graphics.

     setAlpha(int a)
    

    Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.

    http://developer.android.com/reference/android/graphics/Paint.html. Have a look a the documentation.

    Edit:

    Also check this

    https://code.google.com/p/android/issues/detail?id=54105#c1