使用 ImageIO.read 的问题 [英] Problem using ImageIO.read
问题描述
好的,我有一张我正在尝试阅读的图片.问题是 Image.read(file) 返回 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(file) 返回 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 链接文本但它因不是 JPEG 文件:以 0x4d 0x4d 开头"而失败.
- 图片扩展名为 .jpg,但windows 说它是 JPEG 类型?这个令人困惑.
- Ok my environment is Windows 7. I tested with one of those images that comes with Windows and its able to read the image.
- The image1.jpg was created by another system. Now sure what method they are using.
- I tried converting the image into RGB as suggested here link text but it fails with "Not a JPEG file: starts with 0x4d 0x4d".
- The image extension is .jpg, but windows says its a JPEG type? This is confusing.
有人可以帮忙吗?我是新手,不知道如何解决这个问题.
Can someone help with this? I'm new to this, not sure how to fix this.
好的,我刚刚发现 ImageIO.getImageReaders(stream) 返回一个空的迭代器.这意味着它找不到合适的阅读器?我应该如何阅读这张图片?
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 jai-imageio.jar(我知道这不是个好主意).我把它移到了我的项目/库中,它起作用了!我猜这个 jai-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屋!