Skip to content

Documentation / @ripl/canvas / rescaleCanvas

Function: rescaleCanvas() ​

rescaleCanvas(canvas, ctx, width, height): RescaleResult

Defined in: canvas/src/utilities.ts:262

Sizes a canvas element's backing store for the device pixel ratio and returns the coordinate scales mapping logical pixels onto it.

The scales are returned whether or not the backing store needed resizing: they describe the requested logical size, which can change without the scaled integer dimensions changing.

Parameters ​

ParameterTypeDescription
canvasHTMLCanvasElementThe canvas whose backing store is sized.
ctxCanvasRenderingContext2DThe canvas's 2D context, whose transform is reset when the backing store changes.
widthnumberRequested width, in logical pixels.
heightnumberRequested height, in logical pixels.

Returns ​

RescaleResult

The updated coordinate scales.