I read this canvas overview :
The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).
Can anyone explain the canvas more clearly?
And I am confused about the relationship between the canvas and matrix. Does the canvas takes the transformations from the matrix? And I want to know if below function affect on the canvas?
canvas.drawBitmap(bitmap, matrix, paint);
In other words, is the canvas matrix different from the bitmap matrix?
I asked this, because when I'm using canvas.drawBitmap
and then using canvas.concat()
and then drawing any object, this object takes same transformations on canvas, so I think the canvas and bitmap have the same matrix!!
The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).
Canvas is the place or medium where perfroms/executes the operation of drawing, and Bitmap is responsible for storing the pixel of the picture you draw.
Actually, translate moves the entire coordinate system. This has the desired effect of also moving the thing you are drawing. I draw the tree first at (0,0) . Then I translate the origin of the coordinate system to some other spot on the canvas.
They are different. When using the canvas to draw a bitmap providing a matrix, internally, the provided matrix are concatenated to the current canvas matrix.
In other words, calling canvas.drawBitmap(rectBitmap, matrix, paint);
has the same effect of:
canvas.save();
canvas.concat(matrix);
canvas.drawBitmap(rectBitmap, 0, 0, paint);
canvas.restore();
This explain why your object is taking the same transformations because you are calling canvas.concat(matrix);
and after that drawing the object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With