Re: Saving grid to jpeg format

Hi Karan,

Sorry to hear of your continuing problems. This logic
works in the SpreadSheet. All I can think of is that there
may be some delay in Java3D getting initialized. Here's a
hack that might work. In your convertGridToImage() method,
replace:

  BufferedImage image = display.getImage();

with:

  BufferedImage image = display.getImage();
  new visad.util.Delay(1000); // wait one second
  image = display.getImage();

The first call to getImage() will get Java3D started, and
maybe a second later its rendering thread etc will be ready
for action. If it doesn't work, try a longer delay. If you
save many images during a run of your application, you may
only need to do this the first time you save an image.

Please let us know if you continue to have problems.

Good luck,
Bill

karan kapoor wrote:
> 
> Hi All,
> 
> Thanks you for your kind suggesstions.
> We tried as you said in yesterday's mail. We tried to
> create a thread in the captureDialog() method, and in
> that method convertGridToImage(File f) is called.
>      We are able to create a jpeg file of the grid
> but, the entire grid is not saved. We have a 6 X 11
> grid. Only the Bottom line of the grid is saved and is
> visible as jpeg file. We are not able to see the whole
> grid.
>       Our application generates whole grid using VisAD
> and it is fully visible as 6 X 11 grid.But when it is
> saved as jpeg file only bottom line is visible. Please
> help us.
> 
> =====================================================
> 
> public  void convertGridToImage(File f) throws
> FileNotFoundException, IOException, RemoteException,
> VisADException {
>         BufferedImage image = display.getImage();
>         FileOutputStream fout;
>         try {
>             JPEGEncodeParam param
> JPEGCodec.getDefaultJPEGEncodeParam(image);
>             param.setQuality(100, true);
>             fout = new FileOutputStream(f);
>             JPEGImageEncoder encoder
> JPEGCodec.createJPEGEncoder(fout);
>             encoder.encode(image, param);
>            fout.close();
>         }
>         catch (NoClassDefFoundError err) {
>             throw new VisADException("JPEG codec not
> found");
>         }
> 
>     }
> 
>     public void captureDialog() throws VisADException,
> RemoteException{
>         final File f = new File("c:/jpegfile.jpeg");
>         if (f == null) return;
>         Runnable captureImage = new Runnable() {
>             public void run() {
>                 String msg = "Could not save image
> snapshot to file \"" + f.getName() +
>                 "\" in JPEG format. ";
>                 try {
>                     convertGridToImage(f);
>                 }
>                 catch (VisADException exc) {
>                     System.out.println("Error in image
> saving");
> 
>                 }
>                 catch (IOException exc) {
>                     System.out.println("Error in image
> saving");
> 
>                 }
>             }
>         };
>         Thread t = new Thread(captureImage);
>         t.start();
>     }
> 
> =====================================================
> 
> with regards,
> Karan Kapoor.
> 
> __________________________________________________
> Do You Yahoo!?
> Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
> http://im.yahoo.com

-- 
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html


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