Try something like this (without third party GIF/JPEG coders/decoders):

import java.io.IOException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.image.BufferedImage;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;

public class MyJpeg extends HttpServlet
{

////////////////////////////////////////////////////////////////////////////
//////////////
  public void doGet( HttpServletRequest request, HttpServletResponse
response )
              throws IOException
  {
    BufferedImage bi = new BufferedImage( 255, 255,
BufferedImage.TYPE_INT_RGB );
    Graphics g = bi.getGraphics();
    for( int u = 0; u < 255; u++ )
    {
      g.setColor( new Color( u, 128, 255-u ) );
      g.drawLine( 0, u, 255, u );
    }
    g.setFont( new Font( "arial", 0, 50 ) );
    g.setColor( Color.red );
    g.drawString( "Hello world", 5, 50 );
    g.setColor( Color.white );
    g.drawString( "Hello world", 5, 100 );
    g.setColor( Color.black );
    g.drawString( "Hello world", 5, 150 );
    g.setColor( Color.green );
    g.drawString( "Hello world", 5, 200 );

    response.setContentType( "image/jpeg" );
    ServletOutputStream sos = response.getOutputStream();
    JPEGImageEncoder je = JPEGCodec.createJPEGEncoder( sos );
    je.encode( bi );
    sos.close();
    g.dispose();
  }

}

.Dmitry.


> -----Original Message-----
> From: Aaron Porter [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 16, 1999 6:47 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Drawing lines in images!
>
>
> You can use GifServlet. It's at
>
> http://www.metawerx.com.au/aaron.porter
>
> Aaron
>
> > -----Original Message-----
> > From: Groenescheij, Michel
> > [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, June 16, 1999 12:27 AM
> > To: [EMAIL PROTECTED]
> > Subject: Drawing lines in images!
> >
> >
> > Hi all,
> >
> > I'd like to let my servlet produce an image in my browser,
> > which has been provided with multiple lines drawn on it.
> > One way I can think of is sending the coordinates of the lines
> > from the servlet to an applet, which then draws the lines on
> > the image. Does anyone know some better way to do this?
> > Is there any way to generate images directly in servlets?
> >
>
> ______________________________________________________________
> _____________
> 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

___________________________________________________________________________
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