Android Undo Drawing Method On Canvas
I created some code that takes a picture and displays the picture, then the user is able to draw on the picture. I want to implement an undo method. I based my code on many example
Solution 1:
So there are two things you are doing when it comes to Paths
that the user draws.
- In the method
touchUp()
:mCanvas.drawPath(mPath, mPaint);
- In
onDraw()
:canvas.drawPath(p, mPaint);
When you call onClickUndo()
, the onDraw()
things gets undone. But the one in touchUp()
is not undone. That's why your Undo doesn't seem to work. Problem is in line mCanvas.drawPath(mPath, mPaint);
Solution:
Do not draw the mPath
on mCanvas
. When you do this, your mBitmap
gets changed (you are drawing your paths
on the mBitmap
). There is no way to undo this. And this is not what you want. If you want your paths
in your mBitmap
, so that you can save it in a file or so, do this finally (perhaps have a method like save()
and do this in that method).
Post a Comment for "Android Undo Drawing Method On Canvas"