ImageIO 不会正确导入 BufferedImage [英] ImageIO wont import BufferedImage correctly

查看:68
本文介绍了ImageIO 不会正确导入 BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误抛出--

线程Thread-3"中的异常 java.lang.IllegalArgumentException: input == null!在 javax.imageio.ImageIO.read(来源不明)

Exception in thread "Thread-3" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source)

代码--

try {
        playerImage = ImageIO.read(Player.class
                .getResourceAsStream("/toon.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }

文件路径--

H:\workspace\Isaac\resources\toon.png

H:\workspace\Isaac\resources\toon.png

我对此进行了一些研究,但没有一个解决方案对我真正有效.有什么想法吗?

Ive researched this a bit but none of the solutions have really worked for me. any ideas?

推荐答案

如果 Isaac 是您的项目文件夹,那么您的阅读方式应该有效.请检查目录 resources 是否是源文件夹(在 eclipse 中它应该有一个文件夹的图标,上面有一个 java 包的覆盖),如果不是,则右键单击它并转到 构建路径并选择Use as Source Folder.

If Isaac is your project folder, then the way your are reading should work. Please check whether the directory resources is a source folder (in eclipse it should have an icon of a folder with an overlay of a java package), if not then right click on it and got to Build path and choose Use as Source Folder.

您的目录结构应如下所示:

Your directory structure should look something like this:

编译前

H:\workspace\Isaac
├───resources
│       toon.png
│
└───src
        Player.java

编译后

H:\workspace\Isaac
├───bin
│       Player.class
│       toon.png
│
├───resources
│       toon.png
│
└───src
        Player.java

getResourceAsStreambin 中查找图像,而不是在 resources

getResourceAsStream looks for the image in bin and not in the one in resources

这篇关于ImageIO 不会正确导入 BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆