发布于 2025-01-20 18:43:06 字数 859 浏览 0 评论 0原文

我正在尝试拍摄一个场景的快照(本质上是图表制造商)并将其存储为.png文件。但是,由于场景的顶部有菜单栏,我要确保仅捕获菜单栏下方的一部分。我想到使用快照参数来确保这一点,但是无论出于何种原因,快照方法都不接受我的快照帕拍摄者类。

这是采用快照的方法。问题是该场景。Snapshot将不接受快照参数参数。下面的代码将完全接受,它无法“裁剪”包含梅纳布尔人的场景的顶部。

    public void exportDiagram() throws IOException {
        TextInputDialog inputDialog = new TextInputDialog();
        inputDialog.getDialogPane().setContentText("Save image as:");
        inputDialog.showAndWait();
        TextField userInput = inputDialog.getEditor();
        Scene scene = main.getScene();
        SnapshotParameters param = new SnapshotParameters();
        param.setViewport(new Rectangle2D(0, 23, 600, 377));
        WritableImage imgReturn = scene.snapshot(null);
        File file = new File(userInput.getText() + ".png");
        ImageIO.write(SwingFXUtils.fromFXImage(imgReturn, null), "png", file);
    }

I am trying to take a snapshot of a scene (which is essentially a diagram maker) and store it as a .png file. However, as the top part of the scene has menu bars, I want to ensure that only the part of the scene below the menu bars is getting captured. I thought of using Snapshot Parameters to ensure this, but for whatever reason the snapshot method doesn't accept my SnapshotParameters class.

Here is the method that takes the snapshot. The issue is that scene.snapshot will not accept the SnapshotParameters param. The code below will work perfectly accept it isn't able to "crop out" the top part of the scene which contains the menubars.

    public void exportDiagram() throws IOException {
        TextInputDialog inputDialog = new TextInputDialog();
        inputDialog.getDialogPane().setContentText("Save image as:");
        inputDialog.showAndWait();
        TextField userInput = inputDialog.getEditor();
        Scene scene = main.getScene();
        SnapshotParameters param = new SnapshotParameters();
        param.setViewport(new Rectangle2D(0, 23, 600, 377));
        WritableImage imgReturn = scene.snapshot(null);
        File file = new File(userInput.getText() + ".png");
        ImageIO.write(SwingFXUtils.fromFXImage(imgReturn, null), "png", file);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文