Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ImageIO trouble  RSS feed

 
Tomas Toss
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again, I have some mysterious trouble when trying to read images files.



This code works fine when executing it in Eclipse (Yielding the path name,boolean value true, and the string "Image is not null"). However, as soon as I create a jar file and try to execute the program, there is an error. The path name is still printed, and the boolean value is still true, but the string has become "Image is null". (The file is located outside of the jar).

I have been trying to figure out the problem and there seems to be some fault using ImageIO itself. ImageIO.getReaderFileSuffixes() yields a null value when the code is packed inside the jar, but works fine when executed in Eclipse.

The program has been working before, unfortunately I'm not sure when it broke. I did install a new JRE (1.7) last week, but since the code runs in Eclipse using this JRE, I don't believe this is the problem. Do you have any ideas?

Best regards
Tomas
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the file name? Perhaps the suffix isn't enabled by default, and in Eclipse there is added support for it.
 
Tomas Toss
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a .png file, so there shouldn't be any trouble reading it.

The output is:

C:\Users\Tomas\Desktop\Examensarbete\bilderserie\1.png
true
Image is null
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've gone through the ImageIO and a few of the other classes in the package, and I think I found where it goes wrong.

ImageIO.read(File) creates an ImageInputStream by calling createImageInputStream(input). This does not return null, or an IIOException would be thrown.
It then calls ImageIO.read(ImageInputStream). This calls getImageReaders(ImageInputStream). If this iterator has no elements null is returned. So this is where to look at.

getImageReaders(Object) calls getServiceProviders(ImageReaderSpi.class, new CanDecodeInputFilter(input), true) on an instance of IIORegistry. This class has automatic support for ImageReaderSpi.class, and has registered a PNGImageWriterSpi and PNGImageReaderSpi.
The getServiceProviders method is actually defined in IIORegistry's super class ServiceRegistry. This method calls getServiceProviders without the filter, then wraps that iterator in a filtering iterator.

I think the filter is where the problem probably lies. It returns whether or not the PNGImageReaderSpi can decode the file, and apparently it cannot. If this is a bug in the PNGImageReaderSpi class or a fault in the PNG file, I cannot tell you.
 
Tomas Toss
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With your help I found out that it was the external library jai-imageio I'm using that caused the problem (perhaps doesn't work with 1.7?). Removing the library from the project make the program run, but unfortunately I lost the possibility to read .tif images.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!