Hi all,
I'm writing an application that needs to load a few large PNGs as fast
as possible. I've previously been using
javax.imageio.ImageIO.read(File) to get a BufferedImage, but I'm
wondering if there's a faster way? I'm aware that there's
Toolkit.getImage(String) but I have no clue as to which is going to
give me the best performance. Thanks for any tips you can provide.
Thanks,
Andre
Knute Johnson - 14 Jun 2006 18:42 GMT
> Hi all,
>
[quoted text clipped - 7 lines]
> Thanks,
> Andre
Your best bet for file loading performance increase is to get a faster
processor and a faster disk. Beyond that I don't think there is any way
to modify the ImageIO classes to improve performance.
Do you need the complete image loaded at once? Can you load a lower
resolution version and then load your hires asynchronously?
The only other thought I had, which probably won't work, is to use a
BufferedInputStream with a very large buffer (for faster disk I/O) and
then a PipedInputStream to send the data to your ImageIO.read() to
convert it to the BufferedImage asynchronously. All of the extra I/O
will probably be slower but it might be worth a try.

Signature
Knute Johnson
email s/nospam/knute/
Mark Space - 14 Jun 2006 19:56 GMT
> Hi all,
>
[quoted text clipped - 7 lines]
> Thanks,
> Andre
In other applications, I've seen programmers spawn multiple threads to
load lots of data. The idea is that multiple threads will create as
many IO requests as possible, allowing the OS to optimize the IO channel
and load as much as possible.
If you only read one thing at a time with one thread, there's a chance
the OS will preform no read ahead, and only load small bits at a time,
forcing lots of waiting for a slow IO channel.
Besides thumbnails, you could also look at compression. Compressed
images load faster. You could also load low resolution images first,
display them, then load higher resolution images in the background.
jcsnippets.atspace.com - 16 Jun 2006 16:09 GMT
> Hi all,
>
[quoted text clipped - 4 lines]
> Toolkit.getImage(String) but I have no clue as to which is going to
> give me the best performance. Thanks for any tips you can provide.
One thing you could try, is preloading the images in a separate thread (if
that is an option) while you are doing other stuff.
For example, I've once written a small image viewer where, upon opening a
directory, the first, last, next, and previous image were loaded. If a user
wanted to see images one by one, they were always preloaded and therefor
available instantly.
Best regards,
JayCee
--
http://jcsnippets.atspace.com/
a collection of source code, tips and tricks