How to save and restore the default settings of the canvas in JavaScript

1 Answer

0 votes
<canvas id="canvas"></canvas>
<script type="text/JavaScript">   
           
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

ctx.save(); // save default state

ctx.fillStyle = "blue";
ctx.fillRect(20, 20, 100, 100);

ctx.restore(); // restore default state
ctx.fillRect(170, 80, 100, 100);

</script>

 



answered May 28, 2016 by avibootz
...