繁花不似錦
2019-06-09 15:55:41
如何清除畫布以重新繪制在對復(fù)合操作進(jìn)行實驗并在畫布上繪制圖像之后,我現(xiàn)在正在嘗試刪除圖像并進(jìn)行組合。我該怎么做?我需要清除畫布,以重新繪制其他圖像;這可以持續(xù)一段時間,所以我不認(rèn)為每次繪制一個新的矩形將是最有效的選擇。
3 回答

一只斗牛犬
TA貢獻(xiàn)1784條經(jīng)驗 獲得超2個贊
const context = canvas.getContext('2d');context.clearRect(0, 0, canvas.width, canvas.height);

藍(lán)山帝景
TA貢獻(xiàn)1843條經(jīng)驗 獲得超7個贊
用途: context.clearRect(0, 0, canvas.width, canvas.height);
不要使用: canvas.width = canvas.width;
canvas.width
處理轉(zhuǎn)換坐標(biāo)
scale
, rotate
translate
context.clearRect(0,0,canvas.width,canvas.height)
// Store the current transformation matrixcontext.save(); // Use the identity matrix while clearing the canvascontext.setTransform(1, 0, 0, 1, 0, 0);context.clearRect(0, 0, canvas.width, canvas.height); // Restore the transformcontext.restore();
編輯:
100000 iterations averaged 10 times:1885ms to clear2112ms to reset and clear
添加回答
舉報
0/150
提交
取消