How to save the state of canvas and do the undo function the, save () method seems to be of little use.

need to do a picture graffiti function, and then need to undo the function, save () method seems to be useless, checked the data and said that it only saves the state, can not restore the canvas content. no, no, no.
how can I save the operation steps to undo


you need to save the content. You need to save it first.
save is not used to save content, but to save contextual information, such as color, filling, etc.


save () saves only the state of the CanvasRenderingContext2D object and all the properties of the object, excluding the graphics drawn on the object.

give a link to see for yourself https://www.w3cplus.com/canva.

PS: your save and restore codes are not posted, so how can I show you the problem

add:

if you need to implement the function of ctrl + z, ctrl + y, it is impossible to use save/restore.
you can create your own stack, to store your operations. If you need to undo, stack pop, then
rerun again. For performance reasons, when you can rerun base image can not be the initial state, you can
customize several base image

Menu