我正在尝试将图像作为 BufferedImage 加载到我的 java 应用程序中,目的是让它在 JAR 文件中工作。我尝试使用ImageIO.read(new File("images/grass.png"));
which 在 IDE 中有效,但在 JAR 中无效。
我也试过
(BufferedImage) new ImageIcon(getClass().getResource(
"/images/grass.png")).getImage();
由于 NullPointerException,它甚至无法在 IDE 中工作。我尝试在路径中使用 ../images、/images 和 images 来执行此操作。这些都不起作用。
我在这里错过了什么吗?