How to clear the canvas for redrawing

后端 未结 23 2827
粉色の甜心
粉色の甜心 2020-11-21 11:37

After experimenting with composite operations and drawing images on the canvas I\'m now trying to remove images and compositing. How do I do this?

I need to clear th

23条回答
  •  旧巷少年郎
    2020-11-21 12:07

    fastest way:

    canvas = document.getElementById("canvas");
    c = canvas.getContext("2d");
    
    //... some drawing here
    
    i = c.createImageData(canvas.width, canvas.height);
    c.putImageData(i, 0, 0); // clear context by putting empty image data
    

提交回复
热议问题