Reputation: 6282
I'm trying to write a simple lightweight image browser in Java, currently I'm using ImageIO.read(new File(/* PATH_TO_IMAGE */))
to load the images.
Problem is, to load 10 JPEG's takes 10467 milliseconds. This seems much to slow especially when I'm planning on possibly loading hundreds of images.
Is there any faster way to load them?
Also, I'm drawing thumbnails by overriding paintComponent
in a JPanel and painting the thumbnails using Graphics2D, if that makes any difference.
(and feel free to suggest a better way to do this)
Upvotes: 2
Views: 3207
Reputation: 205775
Amplifying on @Thomas Mueller's suggestion regarding thumbails, you can offload the heavy lifting to a SwingWorker
, shown here. See also this answer on resampling.
Upvotes: 3
Reputation: 50087
If you want to display thumbnails, you should consider creating, and storing, thumbnails.
You can't expect to be able to load hundreds of 6 MB files per second. Thumbnails are about 50 KB, and load a lot quicker (where 'load' is reading from the hard disk and decoding them in-memory).
Upvotes: 3