Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dynamically generate Image(s) in Servlets

0 views
Skip to first unread message

jean_t...@my-deja.com

unread,
Oct 26, 1999, 3:00:00 AM10/26/99
to
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


Sent via Deja.com http://www.deja.com/
Before you buy.

Robbie Baldock (real email address at foot of message)

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to
jean_t...@my-deja.com wrote:

>I would like to output from my servlet an image in format GIF that I
>will dynamically generate.

I think you'll want to use a BufferedImage (new to Java 2) - this is
precisely the sort of thing it's provided for.


Robbie


-------------------------------------------------------------
Robbie Baldock
r c b AT e a s y n e t DOT c o DOT u k (you know what to do!)
http://www.rcb.easynet.co.uk/
-------------------------------------------------------------

pron...@my-deja.com

unread,
Nov 18, 1999, 3:00:00 AM11/18/99
to
i'd like to use the gifEncoder class to write the components of my
applet frame to a gif on the applets server. the problems i see our
these:

1. the applet cannot write to the client
2. the gifEncoder uses a local dataOutputStream to write the gif file
3. i cannot pass a java object to a cgi-script

can i somehow write the GifEncoded image to a memory buffer and send
the bytes to my cgi script?

any thoughts, code or ideas are really appreciated, i'm stupmed on this
one.

- b


In article <7v3r9t$lta$1...@nnrp1.deja.com>,


jean_t...@my-deja.com wrote:
> I would like to output from my servlet an image in format GIF that I
> will dynamically generate.
>

Aleksandr Voronkov

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to

Hi!
I have same problem.
Tell me , how i can acquire GifEncoder?
0 new messages