0
votes

im doing a simple paint program.

I'm drawing to a custom Bitmap and then draw this bitmap to the canvas in the onDraw method.

custom bitmap and canvas creation:

bitmap = Bitmap.createBitmap(w - 150,h,Bitmap.Config.ALPHA_8);
canvasa  = new Canvas(bitmap);

when someone touches the screen a circle gets drawn:

canvasa.drawCircle(x, y, 10, paint);

which works fine, but every time the bitmap gets drawn on Screen, every circle has the same color (the paints current color):

@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(bitmap,0,0, paint);
super.onDraw(canvas);
}

So if i have a red circle, change the color to blue and draw another circle, both circles in the bitmap are blue. Why is that? And how do I fix this?

1
read about Bitmap.Config.ALPHA_8pskink
@pskink thanks man.... the one thing i did not check :DVlad de Elstyr

1 Answers

2
votes

For what you are doing, it does not make sense to pass the paint color at the time of drawing to the canvas. This is how the current color of paint is appearing on the canvas. If you check the documents you see this can be null.

Also as has been pointed out in comments, the config of the bitmap is incorrect for what you want to do. I suggest ARGB_8888 is more likely what you need here, so:

Bitmap.createBitmap(w - 150, h, Bitmap.Config.ARGB_8888);

and:

canvas.drawBitmap(bitmap, 0, 0, null);