I want to zoom and pan an HTML5 Canvas by transforming the context using translate()
and scale()
, clearing the canvas, and then redrawing. Note that I am explicitly not calling save()
and restore()
around my transformations.
If I perform the standard ctx.clearRect(0,0,ctx.canvas.width,ctx.canvas.height)
then the entire visible canvas will not be cleared; downscaling or panning may cause this initial rectangle to not exactly cover the drawing area.
If I perform the Webkit-friendly clearing method...
var w=canvas.width;
canvas.width = 0;
canvas.width = w;
...then the cumulative transformation of the context is reset.
How can I best clear the entire canvas context without losing my transformation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…