Fast PNG loading - which mechanism?

Discussion in 'Java' started by abickford@gmail.com, Jun 14, 2006.

  1. Guest

    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
     
    , Jun 14, 2006
    #1
    1. Advertising

  2. wrote:
    > 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.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Jun 14, 2006
    #2
    1. Advertising

  3. Mark Space Guest

    wrote:
    > 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.
     
    Mark Space, Jun 14, 2006
    #3
  4. <> wrote in message
    news:...
    > 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
    --
    http://jcsnippets.atspace.com/
    a collection of source code, tips and tricks
     
    jcsnippets.atspace.com, Jun 16, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page