The idea is that you can paint on the canvas, then store it into a variable and move on with other paintings, etc. Then, if you want, reopen that previously painting on the canvas, from the variable.
There's only one canvas element.
This is how I tried to solve that without a result:
<canvas id="myCanvas" width="500" height="500"></canvas>
-
canvas: HtmlCanvasElement;
ctx1: any;
storedCanvas: HTMLCanvasElement;
ctx2: any;
ngAfterviewInit(){
this.canvas = <HTMLCanvasElement>document.getElementById('myCanvas');
this.ctx = this.canvas.getContext("2d");
}
saveCanvas(){
this.storedCanvas = this.canvas;
}
loadCanvas(){
this.canvas.replaceWith(this.storedCanvas);
}
Whatever I did after using saveCanvas(), the changes affect storedCanvas as well, e.g.:
1) Draw
2) Save
3) Make some changes without saving
4) Load the canvas, the changes from 3) affected storedCanvas as well, meaning canvas and storedCanvas still identical even after the save.
I assume this is not even close to how you're supposed to store and render a canvas.