如何在Javafx中显示Internet的图像(无法正常工作)?

发布于 2025-01-29 08:55:41 字数 417 浏览 4 评论 0原文

我想从API中获取图像的URL。我还获得了想要的图像的URL,但是图像在Javafx场景中没有显示。

String json2=readUrl("https://imsea.herokuapp.com/api/1?q=moon");
images.Images i=gson.fromJson(json2,images.Images.class);
System.out.println(i.getResult1());
String path = i.getResult1();
Image image = new Image(new FileInputStream(i.getResult1()));
img_spaceObject.setImage(image);

*更新:我首先下载图像然后显示它来做到这一点,但是我想要一个简短的版本,如前所述。

I want to take the url of a image from a API, which I did. I also get the URL of the image that I want, but the image doesn't display in the JavaFX Scene.

String json2=readUrl("https://imsea.herokuapp.com/api/1?q=moon");
images.Images i=gson.fromJson(json2,images.Images.class);
System.out.println(i.getResult1());
String path = i.getResult1();
Image image = new Image(new FileInputStream(i.getResult1()));
img_spaceObject.setImage(image);

*Update: I did that by first downloading the image and then displaying it, but I wanted a short version, as I mentioned before.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Smile简单爱 2025-02-05 08:55:41

引用

Image image3 = new Image("http://sample.com/res/flower.png", 100, 0, false, false);

所需的URL到构造函数。

To quote the Javadoc:

Image image3 = new Image("http://sample.com/res/flower.png", 100, 0, false, false);

Just pass your desired URL to the constructor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文