對於畫布的雙重緩衝,建立第二個畫布元素並在其上繪製。之後使用drawImage()方法將影像繪製到第一個畫布上。
// canvas element var canvas1 = document.getElementById('canvas'); var context1 = canvas1.getContext('2d'); // buffer canvas var canvas2 = document.createElement('canvas'); canvas2.width = 250; canvas2.height =250; var context2 = canvas2.getContext('2d'); // create on the canvas context2.beginPath(); context2.moveTo(10,10); context2.lineTo(10,30); context2.stroke(); //render the buffered canvas context1.drawImage(canvas2, 0, 0);
以上是HTML5 Canvas支援雙緩衝嗎?的詳細內容。更多資訊請關注PHP中文網其他相關文章!