I know what it does. If I dont use sometimes I can see the difference in alignments, sometimes I don't. My question is: if canvas.restore
restores the state previous to when it was saved, why aren't the changes made after save and before restore undone? The changes remain. Why?
It removes the change in settings, but not the drawing itself. Settings can include scaling the canvas etc., and it restores the scaling to the initial state when you called canvas. save().
This allows you to restore the state before the most recent entry on the save stack, i.e. it "Pops the current save stack".
Save the canvas contents as a base64 encoded PNG image by calling canvas. toDataURL() and store the encoded string in the page's localStorage. When you want to restore the canvas, you would create an image, set the src to be the value previously stored locally and then draw that image on the canvas.
saveLayer method Null safety blendMode applied. This lets you create composite effects, for example making a group of drawing commands semi-transparent. Without using saveLayer, each part of the group would be painted individually, so where they overlap would be darker than where they do not.
canvas.save
and canvas.restore
undo things like rotation and translation. They don't undo drawing on the canvas. The android canvas works similarly to the HTML5 canvas, so you can look at https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial/Transformations if you need more clarification.
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