VisAD Servlet

Hi everyone,

sorry for the delay on this. I have used VisAD in conjunction with servlets
but priorities changed inthe project, and I let the servlets be for a while.

The point  is, I was generating images from a display - not a VisAD display,
but a JPanel which included a display and a few other panels - and it worked
sort of all right. I then tried to scale the whole thing down to a simple
(understandable) servlet and cannot reproduce what I did on other computer.

The relevant piece of code is this:

    ServletOutputStream servOutStream = response.getOutputStream();

    // set the content type so the browser will be able to interpret
correctly
    response.setContentType( JPG_CONTENT_TYPE );

//Debug info
System.out.println("1");

    // this is the image
   // but won't work...
    //BufferedImage bufImage = (BufferedImage)display.getImage(true);

// then I tried this, copied from other code

    java.awt.Component gp = (java.awt.Component) display.getComponent();

// check the sizes -> don't match!
System.out.println(gp.getWidth()+" "+jframe.getSize().width);

    Image image = (Image)  gp.createImage(300,300);//gp.getWidth ()
,gp.getHeight());
    Graphics g = image.getGraphics();
    gp.paint(g);

    // do some painting to test -> it works!
    g.setColor(Color.green);
    g.fillRect(0,0,120,120);

    BufferedImage bufImage = (BufferedImage)image;

System.out.println("2");

    // make a jpg out of it
    JPEGEncodeParam jepar = JPEGCodec.getDefaultJPEGEncodeParam(bufImage);
    jepar.setQuality( 1.0f, true);
    JPEGImageEncoder jpege = JPEGCodec.createJPEGEncoder(servOutStream) ;
    jpege.encode(bufImage, jepar);
System.out.println("3");

    // and send it to the browser
    servOutStream.flush();
    servOutStream.close();
System.out.println("4");

Unfortunately display.getImage(true); doesn't work. Creating the image by
use of pure force doesn't work here, either. I cannot tell what's the
matter, but have heard in Java 1.4 there isn't such a problem (of having to
create off-line frame and etc...).

Sorry, this isn't much help... I got an example servlet ready to send, but
the most important part - creating the display - won't work.

Util.captureImage() only works when the display is visible.

Cheers,

Ugo


  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: