Hi Deepak,

 The problem is likely to be because you extend JApplet and
 heavyweight components associated with JApplet are not really
 compatible with headless mode. Have a look at
http://weblogs.java.net/blog/ixmal/archive/2006/04/headless_toolki_1.html
 for more details.

 Easiest solution is to use JComponent instead of JApplet.
 However, if this class it supposed to be used in the server
 environment, it should be probably reimplemented to use ImageIO
 instead of Toolkit (so you do not need even JComponent).

Thanks,
Andrew

Deepak Jain wrote:
Hi Andrew,
Really thanks for taking time out and helping me with this. Thanks for
the reply I will look into that. I am stuck with HeadlessException
now.Am also searchin in google for any solution , In case you have time
please have a look @ this.
However I have another exception now.
I have a class Test that extends
public class Test extends JApplet {
//Draws a composite image into a BufferedImage object and then writes it
to the  file.
}

When i run this file outside my webapplication {Jboss server} it runs
fine and it creates a temp file which has the composite image i need
However when i run from my webapp i get *java.awt.HeadlessException* .

Now when i run it in my webapp by instantiating the class
Test render= new Test ();
render.getComposite();

There is no constructor defined in my class Test.
Any help on this is appreciated
Thanks again.
Deepak



On 6/14/06, *Andrew Brygin* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:

    Hi Deepak,

      To be able write GIF files you must have recent beta of jdk 6.0
      You can download it from http://download.java.net/jdk6/binaries/.

      If using jdk 6.0 is not option for you then you might consider
      using JAI plugins. For more information on JAI have a look at
      https://jai-imageio.dev.java.net/.

    Thanks,
    Andrew

    Deepak Jain wrote:
     > Hi Andrew,
     > Bingo it worked, But I need to save the file as jpeg instead of
    gif. Any
     > ideas how can I save it as gif file.
     > Thanks
     > Deepak
     >
     >
     > On 6/14/06, *Deepak Jain* <[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>
     > <mailto: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
     >
     >     Hi Andrew,
     >     Thanks for the reply , I am using jdk 1.5.0_06.
     >     Here are the steps I tried
     >     1. First I created the BufferedImage object
     >     BufferedImage buffered_image =
     >              new BufferedImage (600, 300,
    BufferedImage.TYPE_INT_RGB);
     >     2. Now I create a Graphics2D object fromt the buffer so that
    I can
     >     write it into this bufferedImage object.
     >      Graphics2D buf_image_graphics =
    buffered_image.createGraphics ();
     >     3. Now once I have the graphics2d object I call
     >     drawImage() method using it and construct a composite image.
     >     Once done drawing, I need write the constructed composite
    image in
     >     the buffer object it to the file.
     >     4.Now I create a new file using
     >     File f = new File ("c:\\anImage.gif");
     >     and write BufferedImage object into the file using
     >
     >     try {
     >        ImageIO.write (buffered_image, "gif", f);
     >       } catch (IOException e) {
     >        // TODO Auto-generated catch block
     >        e.printStackTrace();
     >       }
     >
     >     After excuting the above progrm,
     >      A new file c:\\anImage.gif is created but this file is empty?
     >     I dont know where did I go wrong.
     >     Any help is appreciated.
     >     Thanks
     >     Deepak
     >     On 6/13/06, *Andrew Brygin* <[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>
     >     <mailto:[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>>> wrote:
     >
     >         Hi Deepak,
     >
     >           What version of jdk are you using?
     >
     >           ImageIO plugin for writing GIF images is available only
    starting
     >           from jdk 6.0 b39.
     >           If you are using older version please try latest jdk
    6.0 beta.
     >
     >           Also note that GIF  image format directly supports only
    images
     >           with color palette. You are using TYPE_INT_RGB image
    that does
     >           not have palette.
     >           In such case palette will be constructed automatically
    but such
     >           palette might be not ideal especially if original image
    has more
     >           than 256 colors.
     >
     >           If GIF is not strict requirement for you I'd suggest to
    use PNG.
     >           It should work fine with your images (without any
    quality issues)
     >           and it is available since 1.4.2 .
     >
     >         Thanks,
     >         Andrew
     >
     >         Deepak Jain wrote:
     >         >  Hi,
     >         >  I am completely lost with Java2d. I have some how
    managed to
     >         construct a
     >         >  composite image and i dont understand how i did it. Please
     >         find the code
     >         >  below, I was working on one of ur examples.Now i need
    to dump this
     >         >  composite image to a temp file so that i can display
    it on the
     >         >  web-browser using the <img> tag of html. I tried
    BufferedImage
     >         but I am
     >         >  not able to understand what  BufferedImage does, read
    java doc but
     >         >  failed to understand. Please let me know any solution
    for this.
     >         >
     >         >
     >         >
     >         >  import java.awt.Dimension;
     >         >  import java.awt.Graphics;
     >         >  import java.awt.Graphics2D;
     >         >  import java.awt.Image;
     >         >  import java.awt.MediaTracker;
     >         >  import java.awt.RenderingHints ;
     >         >  import java.awt.Toolkit;
     >         >  import java.awt.event.WindowAdapter ;
     >         >  import java.awt.event.WindowEvent;
     >         >  import java.awt.image.BufferedImage;
     >         >  import java.io.File;
     >         >  import java.io.IOException ;
     >         >
     >         >  import javax.imageio.ImageIO;
     >         >  import javax.swing.JApplet;
     >         >  import javax.swing.JFrame;
     >         >  /*
     >         >  <applet code="ACImages" width="600"
    height="300"></applet>
     >         >  */
     >         >  public class ACimages extends JApplet {
     >         >
     >         >     private String m_backGroundImgName =
    "emptyEnclosure.gif";
     >         >
     >         >     private Image backImgObj;
     >         >
     >         >     private final int []backImgDimen = {240,150};
     >         >
     >         >     private String dimentionInfo[] =
     >
     >  {"server_1X_2Y","server_1X_2Y","server_1X_2Y","server_1X_2Y"
     >
     >              
,"server_1X_2Y","server_1X_2Y","server_1X_2Y","server_1X_2Y"};

     >
     >         >
     >         >     private Image eleImgObj[] = new
    Image[dimentionInfo.length];
     >         >
     >         >     private final int MAX_NUM_SLOTS_XDIRECT = 8;
     >         >
     >         >     public void init() {
     >         >         Toolkit tk = getToolkit();
     >         >         backImgObj =
     >
     >  tk.getImage(ACimages.class.getResource(m_backGroundImgName));
     >         >         try {
     >         >             MediaTracker tracker = new MediaTracker(this);
     >         >             tracker.addImage (backImgObj, 0);
     >         >             tracker.waitForID (0);
     >         >         } catch (Exception e) {}
     >         >
     >         >         for(int i = 0; i < dimentionInfo.length; i++) {
     >         >             eleImgObj[i] =
     >         >   tk.getImage
    (ACimages.class.getResource(dimentionInfo[i] +
     >         ".gif"));
     >         >             try {
     >         >                 MediaTracker tracker = new
    MediaTracker(this);
     >         >                 tracker.addImage(eleImgObj[i], 0);
     >         >                 tracker.waitForID(0);
     >         >             } catch (Exception e) {}
     >         >         }
     >         >     }
     >         >
     >         >     public void drawDemo(int w, int h, Graphics2D g2) {
     >         >
     >         >         int iw = 24;
     >         >         int ih = 150;
     >         >         float xx = 0, yy = 10;
     >         >         g2.drawImage(backImgObj, (int) xx, (int) yy,
     >         backImgDimen[0],
     >         >  backImgDimen[1], null);
     >         >         for (int i =0; i < eleImgObj.length ; i++) {
     >         >
     >         >          if(i>MAX_NUM_SLOTS_XDIRECT-1) {
     >         >           xx = 0;
     >         >          }
     >         >             xx += iw;
     >         >             g2.drawImage(eleImgObj[i], (int) xx, (int)
    yy, iw,
     >         ih, null);
     >         >             Image status =getToolkit().getImage(
     >         >  ACimages.class.getResource("Critical" + ".gif"));
     >         >                 try {
     >         >                     MediaTracker tracker = new
    MediaTracker(this);
     >         >                     tracker.addImage(status, 0);
     >         >                     tracker.waitForID(0);
     >         >                 } catch (Exception e) {}
     >         >             g2.drawImage(status, (int) xx+6, (int)
    yy+6, 13,
     >         13, null);
     >         >         }
     >         >     }
     >         >
     >         >
     >         >     public void paint(Graphics g) {
     >         >         Graphics2D g2 = (Graphics2D) g;
     >         >         Dimension d = getSize();
     >         >         g2.setBackground(getBackground());
     >         >         g2.clearRect(0, 0, d.width, d.height);
     >         >
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
     >         >
    RenderingHints.VALUE_ANTIALIAS_ON);
     >         >         g2.setRenderingHint (RenderingHints.KEY_RENDERING,
     >         >
    RenderingHints.VALUE_RENDER_QUALITY );
     >         >         drawDemo( d.width, d.height, g2);
     >         >
     >         >     }
     >         >
     >         >     private void writeToFile() {
     >         >         BufferedImage buffered_image =
     >         >          new BufferedImage (600, 300,
    BufferedImage.TYPE_INT_RGB );
     >         >         Graphics2D buf_image_graphics =
     >         buffered_image.createGraphics ();
     >         >         System.out.println("buffered_image
    :"+buffered_image);
     >         >         Dimension d = getSize();
     >         >         buf_image_graphics.setBackground(getBackground());
     >         >         buf_image_graphics.clearRect(0, 0, d.width,
    d.height);
     >         >
     >
    buf_image_graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
     >         >
    RenderingHints.VALUE_ANTIALIAS_ON);
     >         >         buf_image_graphics.setRenderingHint(
     >         RenderingHints.KEY_RENDERING,
     >         >
    RenderingHints.VALUE_RENDER_QUALITY);
     >         >         drawDemo(d.width, d.height, buf_image_graphics);
     >         >         File f = new File ("c:\\anImage.gif");
     >         >         try {
     >         >    ImageIO.write (buffered_image, "gif", f);
     >         >   } catch (IOException e) {
     >         >    // TODO Auto-generated catch block
     >         >    e.printStackTrace();
     >         >   }
     >         >
     >         >         System.out.println("buffered_image
    :"+buffered_image);
     >         >
     >         >     }
     >         >
     >         >     public static void main(String argv[]) {
     >         >         final ACimages demo = new ACimages();
     >         >         demo.init();
     >         >         JFrame f = new JFrame("Java 2D(TM) Demo -
    ACimages");
     >         >         f.addWindowListener (new WindowAdapter() {
     >         >             public void windowClosing(WindowEvent e)
     >         {System.exit (0);}
     >         >         });
     >         >         f.getContentPane().add("Center", demo);
     >         >         f.pack();
     >         >         f.setSize(new Dimension(600,300));
     >         >         f.show();
     >         >         demo.writeToFile ();
     >         >     }
     >         >  }
     >         >
     >         >
     >         >  --
     >         >  Bad boy for life !!!
     >         >
     >
    ===========================================================================

     >         >  To unsubscribe, send email to [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>
     >         <mailto:[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>> and include in the
     >         >  body of the message "signoff JAVA2D-INTEREST". For general
     >         help, send
     >         >  email to [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]> <mailto: [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>>
     >         and include in the body of the message
     >         >  "help".
     >
     >
     >
     >
     >     --
     >     Bad boy for life !!!
     >
     >
     >
     >
     > --
     > Bad boy for life !!!




--
Bad boy for life !!!

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to