canvasrenderingcontext2d.restore()
基础库 或更高版本; 若版本较低,建议采取 兼容处理 。
支小宝客户端 支持
安诊儿客户端 支持
主体: 企业支付宝小程序 、 个人支付宝小程序
恢复之前保存的绘图上下文。
效果示例
代码示例
默认标题0
效果示例
.js
.axml
page({
oncanvasready() {
my.createselectorquery().select('#canvas').node().exec((res) => {
const canvas = res[0].node
const ctx = canvas.getcontext('2d')
// 保存当前绘图上下文
ctx.fillstyle = 'red'
ctx.save()
ctx.fillstyle = 'green'
ctx.fillrect(10, 10, 100, 100)
// 恢复绘图上下文。fillstyle 将变为保存的绘图上下文中的红色
ctx.restore()
ctx.fillrect(150, 40, 100, 100)
})
}
})
<canvas id="canvas" type="2d" onready="oncanvasready">canvas>