cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jens Lorenz" <jens.lor...@interface-projects.de>
Subject Re: ImageReader
Date Mon, 08 Jul 2002 15:00:47 GMT
----- Original Message -----
From: "Bert Van Kets" <bert@vankets.com>
To: <cocoon-dev@xml.apache.org>
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
saw
> 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
GIF
> reader
>
(http://java.sun.com/products/java-media/jai/forDevelopers/jaifaq.html#fil
eformat).
> 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
hints
> 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)

<snip/>

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 );
try
{
  tracker.waitForID( 0 );
}
catch ( InterruptedException e )
{
  e.printStackTrace();
  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();

<snip/>

> 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
way
> the users can upload a whole scale of image types that would
automagically
> be transformed to another type (JPG, GIF, PNG, ...).  How would I
implement
> 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
to
> generate this component easily (I think).
>
> Bert
>

Regards,


Jens

--

jens.lorenz at interface-projects dot de

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


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message