Drawing to the canvas
- by Mattl
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.