Android, Canvas: How to Clear (Delete Contents Of) a Canvas (= Bitmaps), Living in a Surfaceview

Android, canvas: How do I clear (delete contents of) a canvas (= bitmaps), living in a surfaceView?


How do I clear (or redraw) the WHOLE canvas for a new layout (= try at the game) ?

Just call Canvas.drawColor(Color.BLACK), or whatever color you want to clear your Canvas with.

And: how can I update just a part of the screen ?

There is no such method that just update a "part of the screen" since Android OS is redrawing every pixel when updating the screen. But, when you're not clearing old drawings on your Canvas, the old drawings are still on the surface and that is probably one way to "update just a part" of the screen.

So, if you want to "update a part of the screen", just avoid calling Canvas.drawColor() method.

How to erase previous drawing on Canvas?


canvas.drawColor(0, Mode.CLEAR);

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

Android Canvas Clear with transparency

Use the following.

 canvas.drawColor(Color.TRANSPARENT,Mode.CLEAR);

Clear the canvas images or paint in android

Try some thing like this in your
clearing method like:

((YourDrawingClass)YourView).clear();

Android SurfaceView not retaining previously drawn objects

The SurfaceView is double- or triple-buffered. The previous contents are "preserved" in the sense that the system doesn't go out of its way to clear older buffers, but you can't rely on that behavior.

If you specify a dirty rect, the framework will render whatever you ask, then copy the non-dirty region from the previous buffer on top of the new buffer.

The system is allowed to expand the dirty rectangle -- the Rect you pass to lockCanvas() may be updated. You're required to redraw every pixel inside it.

For a (somewhat eye-searing) example of this in action, see "Simple Canvas in TextureView" in Grafika.

For more details on how the system works, see this article.



Related Topics



Leave a reply



Submit