ImageIO Problems

I’ve been having some problems with ImageIO, I thought I’d share. First off, it seems to trash the alpha in my images I load and make them opaque in some instances, and on my brother’s Mac, he gets this exception when trying to load any image:


javax.imageio.IIOException: Unknown row filter type (= 11)!  
at com.sun.imageio.plugins.png.PNGImageReader.decodePass(PNGImageReader.java:1196) 

at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(PNGImageReader.java:1276) 

at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1362) 

at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1530)  
at javax.imageio.ImageIO.read(ImageIO.java:1384) 

at javax.imageio.ImageIO.read(ImageIO.java:1348)  
at com.gamelizard.util.a.a(Unknown Source) 

at com.gamelizard.util.GLApplet.e(Unknown Source)  
at com.gamelizard.util.GLApplet.run(Unknown Source)  
at java.lang.Thread.run(Thread.java:552) 
image: http://www.gamelizard.com/bin/com/gamelizard/util/lizard2.png 
javax.imageio.IIOException: Error reading PNG image data  
at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1370) 

at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1530)  
at javax.imageio.ImageIO.read(ImageIO.java:1384) 

at javax.imageio.ImageIO.read(ImageIO.java:1348)  
at com.gamelizard.util.a.a(Unknown Source) 

at com.gamelizard.util.GLApplet.e(Unknown Source)  
at com.gamelizard.util.GLApplet.run(Unknown Source)  
at java.lang.Thread.run(Thread.java:552) 
Caused by: javax.imageio.IIOException: Unknown row filter type (= 11)!  
at com.sun.imageio.plugins.png.PNGImageReader.decodePass(PNGImageReader.java:1196) 

at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(PNGImageReader.java:1276) 

at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1362) 

... 7 more

Here’s the code that cause the problem

Image src = null;
try {
      src = javax.imageio.ImageIO.read(resource);
}
catch (Exception e) {
    System.err.println("image: " + resource.toString());
      e.printStackTrace();
      return null;
}

Here’s code that works fine without ImageIO:


Image src = Toolkit.getDefaultToolkit().createImage(resource);
mt.addImage(src, 0);
try {mt.waitForAll();}
catch (InterruptedException e){
      e.printStackTrace();
}

Interesting huh? Using MediaTracker also fixes the exception on Mac OS X.

Are the images stored in a jar file? If so, search the forum for “ImageIO bug”.

nope

Please create a test case and file a bug for Sun’s vm.

For the Apple vm, it’d be a good idea to ask on Apple java-dev forum:
http://lists.apple.com/mailman/listinfo/java-dev

And they’ve got a bunch of info here, too:
http://lists.apple.com/mailman/listinfo/java-dev

“Unknown row filter type (= 11)!”

That’s usually due to ImageIO’s b0rked streaming. You can work around that problem by letting a freshly created BufferedInputStream care about the actual loading.

BufferedImage i = ImageIO.read(new BufferedInputStream(getClass().getResourceAsStream(path)));

I’ve had ImageIO throw a fit with quite alot of different valid png formats =/

But then, i’ve had PSP8.1 do the same, so it isn’t just Sun who can write b0rked png codecs =)

Ye, well the funny thing is that ImageIO has only problems with some images if you let ImageIO care about the loading. So uhm… the decoder seems to be actually pretty good (all pngs I ever made are decode-able… if I use that new BufferedInputStream trick).

well I’m just glad that MediaTracker handles it all for me :wink: