How to clear the canvas for redrawing

后端 未结 23 2867
粉色の甜心
粉色の甜心 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:18

    If you use clearRect only, if you have it in a form to submit your drawing, you'll get a submit instead the clearing, or maybe it can be cleared first and then upload a void drawing, so you'll need to add a preventDefault at the beggining of the function:

       function clearCanvas(canvas,ctx) {
            event.preventDefault();
            ctx.clearRect(0, 0, canvas.width, canvas.height);
        }
    
    
    
    

    Hope it helps someone.

提交回复
热议问题