html5-canvas Clearing the screen Raw image data


It's possible to write directly to the rendered image data using putImageData. By creating new image data then assigning it to the canvas, you will clear the entire screen.

var imageData = ctx.createImageData(canvas.width, canvas.height);
ctx.putImageData(imageData, 0, 0);

Note: putImageData is not affected by any transformations applied to the context. It will write data directly to the rendered pixel region.