cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jens Lorenz" <>
Subject Re: ImageReader
Date Mon, 08 Jul 2002 15:00:47 GMT
----- Original Message -----
From: "Bert Van Kets" <>
To: <>
Sent: Monday, July 08, 2002 4:27 PM
Subject: ImageReader

> Hi Cocoon Guru's,

Sorry, no guru here, but some guy with image loading experience.

> I'm planning on using Stefano's ImageReader reader to generate
> thumbnails.  It took me only a few minutes to implement it, but then I
> it only supports JPG images.  Is there any possibility to support GIF
> images or other formats as well?  I found that JDK 1.4 jai implements a
> reader
> Using this I could convert GIF images to JPG for the thumbnail
> presentation.  My Java knowledge is a bit small to do this myself, so
> are welcome.

Here you go. I used this snippet to get the RGB values of an Image.
This does not use JAI, but the AWT Toolkit.
The issue with AWT Toolkit (and probably the reason why Stefano
chose to use the com.sun. class), is that you'll run into problems
with headless unix servers, just like the batik stuff.
The advantage of this is that you don't have to worry what format
the image is in, as long as it is supported. (currently at least
gif, jpg, png and maybe bmp on win32)
Also this solution will most likely eat even more memory than
the original ImageReader. (opening up an X connection, drawing,
getting the drawing result back into memory)


import java.awt.Image;
import java.awt.Toolkit;
import java.awt.MediaTracker;
import java.awt.image.BufferedImage;
import java.awt.Graphics;
import java.awt.image.Raster;

Image source = Toolkit.getDefaultToolkit().getImage( picfile );
MediaTracker tracker = new MediaTracker( new Container() );
tracker.addImage( source, 0 );
  tracker.waitForID( 0 );
catch ( InterruptedException e )
  return null;
width = source.getWidth( null );
height = source.getHeight( null );

BufferedImage image = new BufferedImage( width, height,
BufferedImage.TYPE_INT_RGB );
image.getGraphics().drawImage( source, 0, 0, null );

Raster raster = image.getData();


> There's another thing I could use and that's an image type reader.  It
> takes an image source and converts it to a specified image type.  This
> the users can upload a whole scale of image types that would
> be transformed to another type (JPG, GIF, PNG, ...).  How would I
> this in Cocoon?

Oh. Didn't think of this. But writing is another thing. AFAIK it's not
possible with AWT to write images. So you might be stuck with jpg for
writing - unless you use JAI.

> Gathering knowledge from the thumbnail generator/reader I should be able
> generate this component easily (I think).
> Bert




jens.lorenz at interface-projects dot de

interface:projects GmbH                             \\|//
Tolkewitzer Strasse 49                              (o o)
01277 Dresden                               ~~~~oOOo~(_)~oOOo~~~~

To unsubscribe, e-mail:
For additional commands, email:

View raw message