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
This is what I use, regardless boundaries and matrix transformations:
function clearCanvas(canvas) {
const ctx = canvas.getContext('2d');
ctx.save();
ctx.globalCompositeOperation = 'copy';
ctx.strokeStyle = 'transparent';
ctx.beginPath();
ctx.lineTo(0, 0);
ctx.stroke();
ctx.restore();
}
Basically, it saves the current state of the context, and draws a transparent pixel with copy
as globalCompositeOperation. Then, restores the previous context state.