What is the relationship between canvas and matrix in Android?

I read this canvas review:

The Canvas class contains draw calls. To draw something, you need 4 basic components: a bitmap for storing pixels, a canvas for placing draw calls (write to a bitmap), a drawing primitive (for example, Rect, Path, text, Bitmap) and paint (for describing colors and styles for drawing).

Can someone explain the canvas more clearly?

And I'm confused about the relationship between canvas and matrix. Does the canvas accept transformations from the matrix? And I want to know if the function below affects the canvas?

canvas.drawBitmap(bitmap, matrix, paint);

In other words, is the canvas matrix different from the bitmap matrix?

I asked about this because when I use canvas.drawBitmap, then use canvas.concat(), and then draw any object, this object accepts the same transformations on the canvas, so I think the canvas and the bitmap have the same matrix !!

+4
source share
1 answer

They are different. When using a canvas to draw a raster image that provides a matrix, the internally provided matrix is ​​combined with the current canvas matrix.

In other words, a call canvas.drawBitmap(rectBitmap, matrix, paint);has the same effect:

    canvas.save();
    canvas.concat(matrix);
    canvas.drawBitmap(rectBitmap, 0, 0, paint);
    canvas.restore();

This explains why your object accepts the same transformations because you call canvas.concat(matrix);and after that draw the object.

+4

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


All Articles