Skip to main content

Read embedded thumbnail

4 replies [Last post]
sentry0
Offline
Joined: 2009-03-10

Hi all, forgive me if this has been asked a million times (I did search this site + google) but I have a very simple requirement to read an embedded thumbnail from a jpeg image and display it to the end user.

I currently have a rather simple photo gallery setup that stores images in a database. In the past I had a thumbnail page on a website that would display thumbnails which were dynamically generated from the original source. Obviously, there are real performance implications to this technique, but the galleries were small and basically never viewed so that's how I left things.

Now the galleries are growing quite large and more frequently used so I need to find a way to optimise thumbnail generation. My initial thought was to read the thumbnail from the metadata of a jpeg but I cannot for the life of me figure out how to do this using imageio???

Someone please help me out and point me to some concrete examples.

Message was edited by: sentry0

Message was edited by: sentry0

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
robert engels

see http://forums.java.net/jive/thread.jspa?threadID=28825

On Mar 10, 2009, at 3:19 PM, jai-imageio@javadesktop.org wrote:

> Hi all, forgive me if this has been asked a million times but I
> have a very simple requirement to read an embedded thumbnail from a
> jpeg image and display it to the end user.
>
> I currently have a rather simple photo gallery setup that stores
> images in a database. In the past I had a thumbnail page on a
> website that would display thumbnails which were dynamically
> generated from the original source. Obviously, there are real
> performance implications to this technique, but the galleries were
> small and basically never viewed so that's how I left things.
>
> Now the galleries are growing quite large and more frequently used
> so I need to find a way to optimise thumbnail generation. My
> initial thought was to read the thumbnail from the metadata of a
> jpeg but I cannot for the life of me figure out how to do this
> using imageio???
>
> Someone please help me out and point me to some concrete examples.
> [Message sent by forum member 'sentry0' (sentry0)]
>
> http://forums.java.net/jive/thread.jspa?messageID=336183
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

sentry0
Offline
Joined: 2009-03-10

This is a good place to start so thank you for your reply. What I'm getting stuck on is creating the ImageInputStream object from a byte array. Essentially this is all I have access to as the file is not stored in a conventional filesystem.

I've tried using the IIOByteBuffer object but am frankly confused with it's use. Does this code look like it should work??

IIOByteBuffer buffer = new IIOByteBuffer(picBytes, 0, picBytes.length);

ImageInputStream stream = ImageIO.createImageInputStream(buffer);

marcojacob
Offline
Joined: 2006-07-10

If this doesn't work, try to use ByteArrayInputStream and wrap it with the same method.
That should work. But you have to give the encoded JPEG stream not only part of it.
Are you sure what you got within the byte[]?

sentry0
Offline
Joined: 2009-03-10

Success! Alright, so silly me, I didn't have the the package installed correctly and it was defaulting to the base ImageReader in my JRE so it wasn't finding anything. Everything looks good now, thanks for the help.

I also used ByteArrayInputStream as an argument to create the input stream and it worked like a champ.

Message was edited by: sentry0

Message was edited by: sentry0