Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to erase previous drawing on Canvas?

Tags:

I have a background image (a map) on which I need to regularly draw the you-are-here icon. I use Canvas to draw the icon on top of the map. Assuming that the drawing process is triggered on button click (see code below), how can I erase the previous drawing?

private void displayUserPos(Point userPos) {     Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.ic_yah);     canvas.drawBitmap(marker, (float)userPos.getX(), (float)userPos.getY(), null);     imgView.setImageBitmap(fmOverlay); } 
like image 520
springrolls Avatar asked Aug 05 '11 13:08

springrolls


People also ask

How do you erase a canvas drawing?

To clear the Canvas, you can use the clearRect() method. This method performs pretty well than others for clearing the canvas (such as resetting the width/height, destroying the canvas element and then recreating it, etc..) const context = canvas. getContext('2d'); context.

Is there an eraser tool in canvas?

To erase a complete background in Canva, use the Canva Background Remover tool under “Effects.” To erase or restore certain parts of the background, use the “Erase” or “Restore” function (only applicable after using the Background Remover tool first).

How do I remove objects from canvas?

To delete an Object you don't want: Tap+hold your object in the Import menu on canvas. A popup menu will appear. Tap the Delete button (the trash can).


2 Answers

canvas.drawColor(0, Mode.CLEAR); 

More info http://developer.android.com/guide/topics/graphics/index.html

like image 111
Caner Avatar answered Sep 28 '22 03:09

Caner


canvas.drawColor(0, Mode.CLEAR); 
like image 24
Maxim Avatar answered Sep 28 '22 03:09

Maxim