Hi,

I was also playing with the same thing. GifEncoder has a peculiar
problem, this class extends another class ImageEncoder, therefore, when I
run the servlet, the browser always shows "NoClassDefError" , something
like that for ImageEnocder class, whereas I placed the both ImageEncoder
and GifEncoder class in the same directory (C:\jdk1.3\jre\classes) where
they should be placed so that Java compiler can use the compiled classes.

I have heard this DREADED problem from many users and I placed this
problem in Java Servlet discussion forum.No one could give me the answer.

If you want to convert a graphics object so that the browser can
interpret that, you can go with either GIF or JPEG image.I spent my time
playing with GIF image but I get that DREADED error message.Then, I
switched to converting the image to JPEG image using  Java package.It
works fine.

I am giving u one simple programe which draws two lines and converts it
in JPEG image and the browser can interpret that one.

Hope it helps.

/************************
 * A. S. M Rokanuzzaman *
 * Atmospheric Science  *
 * Archive programme    *
 * ARM database         *
 ************************/

import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.image.*;

import java.io.*;
import javax. servlet.*;
import javax. servlet. http.*;
import java.util.*;
import java. sql.*;
import java.awt.*;


import com.sun.image.codec.jpeg.*;
//import Acme.JPM.Encoders.ImageEncoder;
//import Acme.JPM.Encoders.GifEncoder;
//import com.jrefinery.chart.*;
public class oreilly extends HttpServlet{


 private Statement stm = null;
 private Connection con = null;
 private String URL = "jdbc:odbc:ARM";
 PrintWriter out ;
 String paramValue="";

double xval[] = {11.2,32.9,41.5,61.5,45.6,67.8};
double yval[] = {21.1,21.4,31.5,41.5,56.7,78.9};
double zval[] = {11.1,11.4,21.5,31.5,46.7,58.9};

 public void init(ServletConfig config)
                      throws ServletException
   {

    super.init(config);

    try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con = DriverManager.getConnection(URL,"","");

      }//end try block

    catch(Exception e){

      e.printStackTrace();
      con = null;
      }//end catch block

   } // end init method


public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
                  throws ServletException, IOException
   {

        //here all return values from HTML forms will be declared.

       response.setContentType("image/jpeg");
       ServletOutputStream out = response.getOutputStream();
       BufferedImage image = new BufferedImage(100,100,
                                               BufferedImage.TYPE_INT_RGB);

       Graphics g = image.getGraphics();
       g.setColor(Color.lightGray);
           g.fillRect(0, 0, 100, 100);
       Graphics2D g1 = (Graphics2D)g;
       System.out.println("\n" + xval.length + "\n");
       for(int i = 0; i<xval.length-1; i++){
              g1.setPaint(Color.red);
          g1.draw(new Line2D.Double(xval[i]+20,yval[i]+20,xval[i+1]+20,yval[i+1]+20));
          g1.draw(new Line2D.Double(xval[i]+20,zval[i]+20,xval[i+1]+20,zval[i+1]+20));

        }


       JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
       encoder.encode(image);
       out.close();
     }
     //Process the HTTP Post request
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
                      throws ServletException, IOException {
                      doGet(request,response);
                 }
                               //Get Servlet information
       public String getServletInfo() {
                      return "JPEGServlet Information";
                 }
       }




                        *************************
                        *                       *
                        *  A.S.M. Rokanuzzaman  *
                        *  Computer Science     *
                        *  UND                  *
                        *  Phone:701-777-9352   *
                        *                       *
                        *************************

On Fri, 15 Jun 2001, Yuvaraj Mani wrote:

> I think Jason hunters's Java Servlet Programming has addressed your
> requirement.
> Just visit this link ad see if it suits what you need.
> http://www.servlets.com/jservlet2/examples/ch06/index.html#ex06_08
> Yuvaraj Mani
>
>
>
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> Michael Weller
> Sent: Friday, June 15, 2001 8:49 AM
> To: [EMAIL PROTECTED]
> Subject: [off-topic] create BufferedImage from Graphics
>
>
> Hello everybody!
>
> I want to write a servlet that create a BufferedImage object gets the
> Graphics object from it, draws some some stuff on it and finally prints out
> a gif-image created from that Graphics object.
> I think this is a quite basic question but didn't find a solution in the
> archives at java.sun.com or in the java tutorial.
> How do get a Image or an ImageProducer from a Graphics object (I'm working
> with Acme.JPM.Encoders.GifEncoder to convert the Image to a gif) ?
>
> Thanks in advance.
>
> Michael Weller
>
> ___________________________________________________________________________
> 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
>

___________________________________________________________________________
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