W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
解釋:恢復(fù)之前保存的繪圖上下文。
無
代碼示例 1
<canvas canvas-id="myCanvas" class="myCanvas" />
Page({
onLoad() {
const canvasContext = swan.createCanvasContext('myCanvas');
// 保存默認(rèn)填圖樣式
canvasContext.setFillStyle('red');
canvasContext.save();
canvasContext.setFillStyle('blue');
canvasContext.fillRect(10, 10, 150, 100);
// 恢復(fù)之前保存的狀態(tài)
canvasContext.restore();
canvasContext.fillRect(50, 50, 150, 100);
canvasContext.draw();
}
});
代碼示例 2
<canvas canvas-id="myCanvas" class="myCanvas" />
Page({
onLoad() {
const ctx = swan.createCanvasContext('myCanvas');
ctx.setFillStyle('blue');
ctx.fillRect(0,0,15,15);
ctx.save(); //保存上述設(shè)置的繪制狀態(tài)
//重新定義新的繪制狀態(tài),并繪制矩形
ctx.setFillStyle('#E0E4CD');
ctx.setShadow(10, 10, 4, 'red');
ctx.fillRect(30,0,30,30);
// 恢復(fù)到初始的繪制狀態(tài)繪制圓形,與save()之前畫的圖保持一致
ctx.restore();
ctx.beginPath();
ctx.arc(100, 75, 8, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();
ctx.draw()
}
});
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: