HTML5 Canvas 是否支持双缓冲?
对于 Canvas 上的双缓冲,创建一个第二个 canvas 元素并绘制到其中。之后,使用 drawImage() 方法将图像绘制到第一个 canvas 上,
// 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);
广告