Shreyash Mahajan
Shreyash Mahajan

Reputation: 23606

How to code for the eraser as like paint in android canvas?

In my drawing application, I am doing painting with on canvas with this code:

currentPaint = new Paint();
            currentPaint.setDither(true);
            currentPaint.setColor(0x00000000);
            currentPaint.setStyle(Paint.Style.STROKE);
            currentPaint.setStrokeJoin(Paint.Join.ROUND);
            currentPaint.setStrokeCap(Paint.Cap.ROUND);
            //currentPaint.setStrokeWidth(3);

No i want to implement the eraser as same as paint. Is it possible to do it on canvas ? If yes then Please help me for it.

Thanks.

Upvotes: 0

Views: 2052

Answers (3)

use this code:

mPaint.setMaskFilter(null);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

Upvotes: 0

Raghunandan
Raghunandan

Reputation: 133560

  currentPaint.setAlpha(0xFF);
  currentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

Call invalidate and the draw gets refreshed.

Upvotes: 3

Franziskus Karsunke
Franziskus Karsunke

Reputation: 5208

You could create graphical objects with the color of the background. Then it looks like the things behind the objects are deleted.

Upvotes: 2

Related Questions