【发布时间】:2013-06-05 03:19:53
【问题描述】:
我正在尝试将图像作为 BufferedImage 加载到我的 java 应用程序中,目的是让它在 JAR 文件中工作。我尝试使用 ImageIO.read(new File("images/grass.png"));,它在 IDE 中有效,但在 JAR 中无效。
我也试过
(BufferedImage) new ImageIcon(getClass().getResource(
"/images/grass.png")).getImage();
由于 NullPointerException,它甚至无法在 IDE 中工作。我尝试在路径中使用 ../images、/images 和 images 来执行此操作。这些都不起作用。
我错过了什么吗?
【问题讨论】:
-
图像在哪里?如果您使用的是eclipse,它是否存在于资源目录中?如果您使用的是 NetBeans,它是否存在于 arc 文件夹中
-
使用 Eclipse,images 是它自己的文件夹,在 src 文件夹之外,但在项目文件夹中。
标签: java image jar bufferedimage