2

In my app I am drawing many things on canvas. Before I draw a new figure I want to remove all the previous drawings and start afresh.

In other words I want to perform a NEW-operation as we do it in MS-Paint with a fresh canvas, nothing drawn on it.

How can I achieve such funstionality ? Please help.

Ankit
  • 4,426
  • 7
  • 45
  • 62
  • You could just remove the bitmaps that are currently on the screen by making the bitmaps null, or making a new canvas and put no draw commands after it. I guess it depends on how your code is as well, because I have set up a method to clear images from the screen – kabuto178 Dec 18 '12 at 12:26

2 Answers2

1

The best way to do it is to draw a desired starting color onto your entire canvas. If you want to to be clear, as origionally.

myCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);

Or if you want a white background like MSPaint

myCanvas.drawColor(Color.WHITE); // Will accept any color.
IAmGroot
  • 13,760
  • 18
  • 84
  • 154
0

If you want to clear the Canvas, you can do this:

            protected void onDraw(Canvas canvas) {

                    ...
                    canvas.drawBitmap(fundo, 0, 0, null);
                    ...

In this case, I am drawing the back scene again, but you can "clear" the canvas too using

Canvas.drawColor(Color.BLACK)

Please see this post

Community
  • 1
  • 1
cleuton
  • 165
  • 1
  • 5