[英]can't loading image in Gluon javafx
I have a problem while trying to add image in my scene in the javafx gluon application using the line bellow I put the img.jpg file in the pin folder我在尝试使用下面的行在 javafx gluon 应用程序的场景中添加图像时遇到问题我将 img.jpg 文件放在 pin 文件夹中
Imageview image = new ImageView(new Image("file: img.jpg"));
and also using ("/img.jpg") any suggestions ?并且还使用 ("/img.jpg") 任何建议?
Your image should be stored under src/main/resources
folder according to a Gradle project structure.根据 Gradle 项目结构,您的图像应存储在
src/main/resources
文件夹下。 Usually it should be under the same package as your class, in this case the following code will load the image:通常它应该和你的类在同一个包下,在这种情况下,下面的代码将加载图像:
Image image = new Image(YourClass.class.getResource("img.jpg").toExternalForm());
ImageView imageView = new ImageView(image);
More information about loading resources in Java can be found at https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource(java.lang.String)有关在 Java 中加载资源的更多信息, 请访问https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource(java.lang.String)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.