Drawing to canvas

I am writing an Android application that draws directly on the canvas in the onDraw event in the view.

I draw 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 is that it takes a long time to draw, since the CalculateMyPoint procedure is a rather expensive method.

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

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

+3
1

, CalculateMyPixel() , , 150 000 (HVGA) 384,00 (WVGA), .

, canvas.drawPoint(), , , .

, - , , Canvas.drawBitmap().

. - Bitmap API , .

drawBitmap(), , , .

onDraw(), , . , . , , invalidate() (, (0,0) - (10, 10) , ). , , , ( , postInvalidate() , ).

, , , , , , UI ( ).

+5

Source: https://habr.com/ru/post/1737908/


All Articles