Scale Canvas
Scaling the canvas context
The scaleCanvas()
method scales the canvas from the included point.
The scale
property
You can also set both the scaleX
and scaleY
properties using the scale
property.
Scaling an individual shape
Rather than scaling the entire canvas, you can scale an individual shape using any of these three properties: scale
, scaleX
, or scaleY
.
Layers
Although it may seem slightly counterintuitive, the scaleCanvas()
method can actually be drawn as a layer. This allows for applying canvas transformations when drawing layers.
To do this, set the layer
property to true
, just as you would to make any other shape a layer. In addition, just as you can with any other type of layer, you can give this layer a name using the name
property.
However, whenever you’re done scaling the canvas, you must restore the transformation using the restoreCanvas()
method.
Notes
The scaleX
and scaleY
values are multiples of the canvas’s current width/height (i.e. 1
is the baseline).
To revert to the canvas’s previous state, call the restoreCanvas()
method. However, you do not need to call this method when scaling an individual shape.