Skip to main content
gamedev.net
🔒 Locked

[java] Does ImageIO block?

Started by AbelCorver Feb 23, 2008 at 1:00 PM 4 replies 2.7k views
Original Post
AbelCorver
AbelCorver
Hello, I'm trying to read several images from a JAR file. I created a method, which uses ImageIO.read(InputStream in) to read the image and it directly returns the result. This methods always returns null! This is very strange, because I tried the same thing with a ByteArrayInputStream and worked fine. I also tried a ZipInputStream, but nothing works! Does someone no what's going on? Thanks in advance.
Angex
Angex
Since you can access the files using a byte stream the pathname is probably correct.

What format is the image you're trying to read?

By default only basic image types are supported, like; jpg, gif, png. You can check available formats using ImageIO.getReaderFormatNames()

AbelCorver
AbelCorver
No that's not the problem. ImageIO recognizes the image types (png and jpeg) if I use a ByteArrayInputStream, so why doesn't it work with a simple InputStream??

I don't use this.getClass().getClassLoader().getResourceAsStream(url), because the files are in another JAR file. But what's the difference between the ByteArrayInputStream and the normal InputStream?!?

Ichigo
Ichigo
First of all InputStream is abstract so your probably using some unknown subclass of InputStream. Your problem might depend on what subclass it is.

It would probably help us if you posted some code to show how your getting this mysterious InputStream.
Have a nice day ^^
AbelCorver
AbelCorver
Maybe I found the problem. I read somewhere that ImageIO doesn't load the whole image. I think the image is loaded when you actually USE the image by drawing it somewhere. I call flush() on the BufferedImage, maybe that will help.

I'll send a reply if this worked.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.