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);
}
For more info Click here
Try as below,it can be used to clear the canvas totally.
Declaration should be like this,
and while clearing use
More info http://developer.android.com/guide/topics/graphics/index.html
Just fill in the canvas with a color or image:
If you want to keep certain elements and take certain elements away you can store these in an ArrayList. Then you can add and remove elements from this ArrayList when you want, and then iterate through them in onDraw().
This simply sets an existing Bitmap to all transparent.
I use this to "clear" a Bitmap object that I use to overlay on top of another to show a cropping window.