使用ImageIO.read问题 [英] Problem using ImageIO.read
问题描述
好吧,我有我试图读取图像。问题在于Image.read(文件)返回NULL。
Ok I have an Image that I'm trying to read. Problem is that the Image.read(file) returns NULL.
File file = new File("C:\\images\\image1.jpg");
if(file.exists()){
System.out.println("Image file exists.");
BufferedImage originalImage = ImageIO.read(file);
}
所以图像存在,但ImageIO.read(文件)返回NULL。没有引发的错误没有!怎么回事?
So image exists but ImageIO.read(file) returns NULL. No thrown errors nothing!!! Whats going on?
这是我到目前为止已经试过:
This is what I have tried so far:
- 确定我的环境是Windows 7。我
与这些图像中的一个测试的
与Windows和它的能
读取图像。 - 的image1.jpg被创造
另一个系统。现在知道什么方法
他们正在使用。 - 我试过图像转换成
RGB这里建议<一href=\"http://stackoverflow.com/questions/2408613/problem-reading-jpeg-image-using-imageio-readfile-file\">link文字
但它失败,没有一个JPEG文件:与送出0x4d送出0x4d开始。 - 图像扩展.JPG,但
窗户说,它的一个JPEG类型?这个
令人困惑。
有人能帮助呢?我是新来这个,不知道如何解决这个问题。
Can someone help with this? I'm new to this, not sure how to fix this.
好吧,我只是想通了,ImageIO.getImageReaders(流)返回一个空迭代。这意味着,它没有找到一个合适的读者?我怎么看这个形象?
Ok I just figured out that ImageIO.getImageReaders(stream) returns an empty Iterator. This means that it couldn't find a suitable reader? How am I supposed to read this image?
推荐答案
好吧,因为我换笔记本电脑,我看着我的旧笔记本电脑,发现在jre / EXT / lib这个JAR回力imageio.jar(我知道坏主意)。我把它搬到我的项目/ lib和它的工作!
我想这回力imageio.jar包含其他图像的读者。
Ok since I switched laptops, I looked at my old laptop and found this JAR jai-imageio.jar in the jre/ext/lib (I know bad idea). I moved it to my project/lib and it worked! I guess this jai-imageio.jar contains additional image readers.
这篇关于使用ImageIO.read问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!