Take the 2-minute tour ×


This is my current onDraw() method -

protected void onDraw(Canvas canvas) {


    if(points.size() > 0) {
        //do some stuff here - this is all working ok



Any help appreciated :)

P.S if it's needed, the the class extends SurfaceView and implements SurfaceHolder.Callback

Edit: This is what I have tried in the onDraw() method but it just force closes

if(bitmap != null) {
        canvas.drawBitmap(bitmap, 0, 0, paint);
share|improve this question

2 Answers 2

up vote 3 down vote accepted

Found the answer myself :)

protected void onDraw(Canvas c) {

if(bitmap != null && canvas != null) { 
    c.drawBitmap(bitmap, 0, 0, linePaint);  


bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
canvas = new Canvas(bitmap);

Works exactly as intended, it creates the effect of drawing on top of the old canvas continuously

share|improve this answer

You will have to store the previous image persistently onto a ArrayList, and during ondraw, loop through the ArrayList to redraw all items.

something like this:

for (Graphic graphic : _graphics) {
    bitmap = graphic.getBitmap();
    coords = graphic.getCoordinates();
    canvas.drawBitmap(bitmap, coords.getX(), coords.getY(), null);
share|improve this answer
Isn't there any way that I can create a bitmap image of the canvas and then just draw that next time onDraw() is called? There will a LOT of lines drawn every frame and this way I think is very processor comsuming –  Mark D Oct 28 '10 at 9:55

Your Answer


