Drawing to the canvas

Posted by Mattl on Stack Overflow See other posts from Stack Overflow or by Mattl
Published on 2010-03-21T13:07:24Z Indexed on 2010/03/21 13:11 UTC
Read the original article Hit count: 361

Filed under:
|
|

I'm writing an android application that draws directly to the canvas on the onDraw event of a View.

I'm drawing something that involves drawing each pixel individually, for this I use something like:

for (int x = 0; x < xMax; x++) {
for (int y = 0; y < yMax; y++){
MyColour = CalculateMyPoint(x, y);
canvas.drawPoint(x, y, MyColour);
}
}

The problem here is that this takes a long time to paint as the CalculateMyPoint routine is quite an expensive method.

Is there a more efficient way of painting to the canvas, for example should I draw to a bitmap and then paint the whole bitmap to the canvas on the onDraw event? Or maybe evaluate my colours and fill in an array that the onDraw method can use to paint the canvas?

Users of my application will be able to change parameters that affect the drawing on the canvas. This is incredibly slow at the moment.

© Stack Overflow or respective owner

Related posts about android

Related posts about java