HTML5 Canvas Reference - save()








The save() method pushes the current state to the stack.

Browser compatibility

save() Yes Yes Yes Yes Yes

Javascript Syntax

context.save()

Example

The following code saves and restores the drawing states.


<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width='500px' height='200px'/>
<script type='text/javascript'>
    var stage= document.getElementById('canvas');
    var ctx = stage.getContext('2d');
<!-- ww  w.ja v a 2 s .  c  o  m-->
    ctx.translate(100,100);  
    ctx.save();
    ctx.rotate(Math.PI);  
    ctx.fillText("java2s.com", 10, 10);
    ctx.restore();
</script>
</body>
</html>

The code above is rendered as follows: