I have 2 canvases.Wat I do is I draw shapes(i.e a line) on the second canvas.When I want to apply transformations(rotate,scale,etc) to this drawn line, I modify the context of first canvas and draw my second canvas on it.Works perfectly.Now when i want to again draw shapes(i.e a line) on second canvas (with transformations),I draw first canvas on second and draw a line on it.Works perfectly fine.Now the problem occurs.When i again want to apply transformations(rotate,scale,etc) to this line i modify the context of first canvas and draw second canvas on it.But this time,I get abrupt changes when I draw on first canvas(draw second canvas).This is due to the transformations applied by drawing 1st canvas on the second and again drawing second canvas to first.Is there a way to change(reset or modify) anything thats already drawn on canvas?
var cantem = document.getElementById('canvasTemp1'); //second canvas
var ctxtem = cantem.getContext('2d');
var canMan = document.getElementById('canvasTempMan'); //first canvas
canMan.style.visibility = "visible";
var ctxcanman = canMan.getContext('2d');
var sWidth = getCanvasWidth(); //returns canvas width
var sHeight = getCanvasHeight(); //returns canvas height
canMan.height = sHeight;
canMan.width = sWidth;
cantem.style.visibility = "hidden";
ctxcanman.setTransform(1, 0, 0, 1, 0, 0);
ctxcanman.clearRect(0, 0, cantem.width, cantem.height);
ctxcanman.translate(sWidth / 2, sHeight / 2);
ctxcanman.scale(ZoomFactor, ZoomFactor);
ctxcanman.rotate(RotateAngle * Math.PI / 180);
ctxcanman.translate(-sWidth / 2, -sHeight / 2);
ctxcanman.drawImage(cantem, 0, 0, cantem.width, cantem.height, OffsetX, OffsetY, sWidth, sHeight);
ctxcanman.save();
Now here I draw my first canvas to second-->
var can = document.getElementById('canvasTempMan');
can.style.visibility = "hidden";
var cantem = document.getElementById('canvasTemp1');
var ctxannotate = cantem.getContext("2d");
ctxannotate.setTransform(1, 0, 0, 1, 0, 0);
ctxannotate.clearRect(0, 0, cantem.width, cantem.height);
ctxannotate.save();
ctxannotate.drawImage(can, 0, 0, cantem.width, cantem.height, OffsetX, OffsetY, can.width, can.height);
I draw(shapes i.e line) on my second canvas using mouse events and simple context functions like moveTo,lineTo,etc.