How to erase previous drawing on Canvas?

springrolls picture springrolls · Aug 5, 2011 · Viewed 47.8k times · Source

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);
}

Answer

Caner picture Caner · Aug 5, 2011
canvas.drawColor(0, Mode.CLEAR);

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