2

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)

Josh
  • 6,046
  • 11
  • 52
  • 83
  • Are you loading the files serially? – Greg Kopff May 15 '12 at 03:57
  • What kind of numbers do you get if you use multiple threads? Have you looked at doing the i/o yourself, separately and first, so that you can profile how long it takes to do the raw ImageIO decoding? – Greg Kopff May 15 '12 at 04:07
  • Is your thumbnail generation and drawing included in your original timings? – Greg Kopff May 15 '12 at 04:08
  • 2
    *"between 2 and 6 MB."* How big in pixels? JPEG means there could be a 10x compression factor between one JPEG & the next, so 'file size' is not a good measure of how large the images are in pixels. – Andrew Thompson May 15 '12 at 04:33

2 Answers2

3

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

Thomas Mueller
  • 48,905
  • 14
  • 116
  • 132
3

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045