I have an applet that generates a Image using Applet.createImage(). A
PixelGrabber is used to get the raw pixel data, and that along with the
image's width and height is sent to a Servlet. The Servlet's job is to write
the image out as a JPEG file.

I developed the Servlet on a Windows box using Java Web Server 2.0, but the
Servlet is deployed on an Apache web server running on Linux, with NO
windowing system installed. The Servlet was originally written to create an
unmanaged Frame and use that to create an Image, which was populated using
the pixel data as a MemoryImageSource. The problem is, when the Servlet
creates the Frame, the JVM tries to access a non-existant X-Server.

So, I need to know how to create an Image without using a Component.

In the Applet, I use the following code to create the Image, and then get
the pixel values:

    Image backgroundImage = createImage(bounds.width, bounds.height);
    ...

     int pixels[] = new int[bounds.width * bounds.height];

    PixelGrabber pg = new PixelGrabber(backgroundImage, 0, 0, bounds.width,
bounds.height, pixels, 0, bounds.width);
     pg.grabPixels();

The pixels array, along with the width and height, are then passed to the
Servlet. I've been experimenting with using the following code to create an
Image in the Servlet:

     DataBufferInt db = new DataBufferInt(pixels, width * height);
     BandedSampleModel sm = new
BandedSampleModel(BufferedImage.TYPE_INT_RGB, width, height, 1);
     Raster r = Raster.createRaster(sm, db, new Point(0, 0));
     BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
     image.setData(r);

I'm getting EOF errors in this code. Problem is, I have no idea what TYPE of
image to use (TYPE_INT_RGB is a guess), and I also don't know how many bands
to use (and BandedSampleModel is a guess, too). I also don't have a clue as
to how to find these things out. Image, as returned by Applet.createImage(),
is not a BufferedImage and doesn't have an image type associated with it
that I can find. Any ideas?

Can I quickly create a BufferedImage from Applet.createImage() within the
Applet, from which I can get the type? What SampleModel should I use? Is
there a better Raster.createXXX method I should be using? Is the above
approach the best way to do it, or is there a simpler way?

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to