I think that gc.scale(2,2) will scale the following things that you draw on the canvas 2 times, rather than existing things that you already painted.
If you want to scale the canvas, you can set the transform on the canvas, not the graphics context.
canvas.setScaleX(2); canvas.setScaleY(2);
If you want the scaled canvas to appear in layout calculations for layout managers, you can wrap it in a group, and if you want to zoom in on a scaled canvas where part of the canvas is cropped, you can either place the canvas in a ScrollPane and define a window for it view, or set the clip to the canvas node.
Pixel Issues Update
To avoid pixel problems when zooming in, I think you will need to record all the graphic commands that have been drawn so far, and then when you want to change the scaling factor, clear the canvas, apply a new scale to the canvas, and then play all graphic commands. Perhaps some format can be used to write graphic commands, for example, svg.
Or you could just use the scene graph and draw on this rather than on the canvas, then you will also not have pixel problems.
I think itโs important to note here that the canvas should be a kind of immediate fire mode and forget, and not a drawing service in save mode, such as a scene graph.
source share