save表示保存save函数之前的状态,restore表示获取save保存的状态
Your browser does not support the HTML5 canvas tag.
$(function() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext('2d');
ctx.fillStyle = "green";
ctx.save()
ctx.fillStyle = "red";
ctx.scale(2, 2)
ctx.fillRect(10, 10, 150, 100) // 红色矩形,尺寸放大一倍
ctx.restore()
ctx.fillRect(50, 50, 150, 100) // 绿色矩形,尺寸没有放大
ctx.draw()
})
相关链接
评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。
发表评论