Hi, I was using ImageIO for my project, and it all worked fine until I webstarted it. Then suddenly gif images started to look weird, while 24 bit pngs didn’t load at all, but instead caused an exception to be thrown.
That bothered me a lot, since I didn’t wanna go back to the toolkit/mediatracker combo because I was copying the image into a compatible bufferimage for hardware acceleration and wanted to do this without any dependencies to Components (Need an ImageListener for MediaTracker)
Finally last day brackeCoB from devshed.com posted the same problem, and his conclusion was that the images weren’t fully loaded.
So I tried the following workaround, that seems to do the trick:
Instead of
BufferedImage src = javax.imageio.ImageIO.read(ImageLoader.class.getClassLoader().getResourceAsStream(resource));
I wrap the ressource stream in a BufferedInputStream:
BufferedImage src = javax.imageio.ImageIO.read(
new BufferedInputStream(ImageLoader.class.getClassLoader().getResourceAsStream(resource)));
The problem seems to be that ImageIO doesn’t keep reading if it can’t get all of the data in one read().