SO, given a MemoryImageSource, how do I create an Image without touching a
Frame? Using the default toolkit doesn't seem to help at all. I'm sure this
all has to do with ImageProducers and consumers, and I'll be trying to find
info and examples how to use them, but if anyone can quickly post an example
or offer alternatives or suggestions, that would be extremely helpful.
Thanks in advance.
Luke
Steve M wrote in message <7u5iip$3ja$1...@autumn.news.rcn.net>...
What's happening is an Image is created by an applet (just using
Applet.createImage(width, height)). Stuff gets drawn into the image in the
applet, and then I use a PixelGrabber to get the Image pixels into an int
array. I then send the width, height and pixels down to the Servlet, which
uses the pixel array as a MemoryImageSource, and that's my ImageProducer.
So: when I call Applet.createImage, is that returning a BufferedImage? If
so, then I could cast the result of Applet.createImage to BufferedImage,
call BufferedImage.getType, and then pass that to the Servlet as well as the
Image's width, height and pixels, and then the Servlet could instantiate a
BufferedImage using the (width, height, type) constructor.
Barring that, a) is the type of Image returned by Applet.createImage
platform-independent, and if so b) what is it?
(btw I'm not going to be drawing into the Image so I don't need to do a
getGraphics() on it. I'm converting the Image to JPEG and writing it out on
the server.)
Luke Webber <lu...@webber.com.au> wrote in message
news:7u5plh$1o9s$1...@arachne.labyrinth.net.au...
Dimitri
Steve M <nos...@mapson.com> wrote:
: I want to create an Image in a servlet running on Linux Apache JServ. I
I have tried the following:
----------------------------------------------------
I would like to output from my servlet an image in format GIF that I
will dynamically generate.
I have acquired a class GifEncoder from ACME. It outputs in a
OutputStream an Image. Great stuff!
Now my problem is how can I generate an Image from my servlet?
I have tried the following:
class myServlet...
{
...
private void OutGIFString(String sOut, OutputStream out) throws
IOException
{
int w = 200;
int h = 50;
int size = width * height;
int pixels[] = new int[size];
for (int i = 0; i < size; i++) {
pixels[i] = Color.black.getRGB();
}
MemoryImageSource source = new MemoryImageSource(width, height,
pixels, 0, width);
Toolkit tlk = Toolkit.getDefaultToolkit();
Image Img = tlk.createImage(source);
Graphics g = Img.getGraphics();
g.setColor(Color.red);
g.setFont(new Font("TimesRoman", Font.BOLD, 12));
g.drawString(sOutput, 10, 50);
GifEncoder GIFEnc = new GifEncoder( Img, out );
}
...
----------------------------
When I run this application I get:
java.lang.IllegalAccessError: getGraphics() only valid for images
created with createImage(w, h)
at sun.awt.windows.WImage.getGraphics(WImage.java:32)
at ImageServer.ImageServer.OutputGIFString(ImageServer.java,
Compiled Code)
at ImageServer.ImageServer.handleRequest(ImageServer.java,
Compiled Code)
at ImageServer.ImageServer.doGet(ImageServer.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at
com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
at
com.sun.web.core.InvokerServlet.service(InvokerServlet.java:169)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at
com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
at com.sun.web.core.Context.handleRequest(Context.java:375)
at
com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:135)
-------------------------
How can I create the Image?
createImage(w, h)is a method from Component, which is an abstract class.
From an Applet it would be simple to create the image but how can I
create it from a Servlet?
Any help would be greatly appreciated. Thanks...
Jean
----------------------------------------------------
In article <7v3cb1$b38$2...@nntp6.atl.mindspring.net>,
Sent via Deja.com http://www.deja.com/
Before you buy.