Fast PNG loading - which mechanism?

A

abickford

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
 
K

Knute Johnson

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

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.
 
M

Mark Space

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

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.
 
J

jcsnippets.atspace.com

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top