How Do We Save and Restore the Canvas State?

To save (push) the current state to the stack, call:

context.save()

To restore the canvas by “popping” the last state saved to the stack, use:

context.restore()

Get HTML5 Canvas, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.