canvas save and restore

var canvas = document.getElementById(id);

if (canvas == null)

return false;

var context = canvas.getContext("2d");

context.fillStyle = "red";

context.save(); //保存了当前context的状态

context.fillStyle = "black";

context.fillRect(0, 0, 100, 100);

context.restore();//恢复到刚刚保存的状态

context.fillRect(0,120,100,100);

你可能感兴趣的:(canvas save and restore)