gpt4 book ai didi

Java 保存图像

转载 作者:行者123 更新时间:2023-11-30 01:59:14 24 4
gpt4 key购买 nike

我编写了一个为我生成图像的程序。到目前为止,这有效,保存保存。

在我想要保存的方法中,我有一个 WritabelImage我做了一个BuffertImageSwingFXUtils.fromFXImage () 。在Intellij的调试器中我也可以看到它,它确实在那里。

然后我将输出路径创建为 URI 并将其传递给 Fil对象。

ImageIO.write ()我想将两者结合并保存。但这是行不通的。路径退出。我尝试使用直接 URI 以及 uri.getPath ()

我只是不知道如何继续。你能帮我吗?

try {
String path;
URI uri;
uri = this.getClass().getResource("").toURI();
path = uri.toString().replace("foo/bar/foobar/generate/", "generate/out/" + name + ".png");
uri = URI.create(path);
File outputFile = new File(uri.getPath());
BufferedImage bImage = SwingFXUtils.fromFXImage(writableImage, null);
System.out.println("Saved");
ImageIO.write(bImage, ".png", outputFile);

} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (URISyntaxException e) {
e.printStackTrace();
}

最佳答案

格式名称参数不应包含点。简单地尝试 "png"

关于Java 保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53457800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com