JavaFX 图像可以保存得比实际更大吗?

Can JavaFX images be saved larger than it is?

我决定制作一个应用程序,基本上根据输入的测量值在 canvas 上为人们绘制特定图像。然后我希望此人能够以更大的格式打印出此图像(或另存为更大的 JPEG、PNG、PDF 文件)。

所以在屏幕上它基本上是像素问题,但在打印上它会是几英寸长,如果这一切都有意义的话?

可以吗?

谢谢!

我已经想出了如何缩放图像以将其保存为更大的格式,所以这是为那些仍在努力解决问题的人准备的。

    // Create the canvas
    Stage primaryStage = new Stage();
    Group root = new Group();
    Canvas canvas = new Canvas(500, 600);              
    GraphicsContext gc = canvas.getGraphicsContext2D();       
    drawShapes(gc);
    root.getChildren().add(canvas);
    primaryStage.setScene(new Scene(root));
    primaryStage.show();

    /* If you're going to scale your image by 2, 
    * for example, make sure your image size is large 
    * enough to contain the new image. As you can see, 
    * the image size is double the canvas size. */

    WritableImage wim = new WritableImage(1000, 1200);
    SnapshotParameters spa = new SnapshotParameters();

    // Scale the x and y axis by a factor of 2

    spa.setTransform(Transform.scale(2, 2));
    canvas.snapshot(spa, wim);

    File file = new File("CanvasImage.png");

    try {
        ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", file);
    } catch (Exception s) {
    }