I’ve been trying to alter the Android (v3.0 Honeycomb) API Demo FingerPaint (API >= 11) to include a working erase option that removes the last drawn path.
The erase in the API demo doesnt work well, in v3.0 is crashes, in v3.1 is draws a black box while only partially erasing the path (a bug has been raised not sure if it has been resolved in v3.2 [not out for Xoom device in UK]).
My code is as follows:
public void eraseLastPath() {
if (!mPaths.isEmpty()) {
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mCanvas.drawPath(mPaths.pop(), mPaint);
invalidate();
}
}
This somewhat works but leaves an outline of the drawn path on the canvas. e.g.
this:

is erased to look like this:

What am I missing? Is there a better way to erase paths?
Any help is much appreciated.
Thanks
Joe
Try to set mPaint anti-alias on.
Edit:
The proper way to erase a path is to store all strokes into an ArrayList and then remove the unwanted one and redraw everything. The method used in the question is not really deleting a path but more like drawing another colour over it, but then anti-alias would not work the same as with the first colour.
Each path needs to be a member object in a new class “stroke”, which also has colour, paint, filters etc stored. In this way all drawing can be restored and it can have infinite undo.