Re: getImage of DisplayImplJ2D

Hi Astrid,
 
I have similar call to getImage(), except that the method 
(as followed) to invoke the display.getImage() does not 
explicitely return the BufferedImage, and it works. Instead, 
the BufferedImage is declared external to the method, so that
it can be obtained at a later stage.

I suspect you problem could be rooted from the fact that
your getBufferedImage() returns the VectorImage() immediately, 
and Java is compelled to return the values as soob as it 
had submited the command to run the thread, irrespective of 
the status of complection of the tread! (Note that, as
it is, there is no guarantee of synchronization between 
the thread that invoke the getImage(), and the thread that 
actually assign the value to the BufferImage).
   
  
    ....
    public BufferedImage bimg; 
    ....
    ....
    
   
    // *************************************************
    // * public void invokeGetImage()                  *
    // * This is needed to capture VisAD images        *
    // *************************************************
    public void invokeGetImage()
    {
       // ************************************
       // *  Make a thread to do the job     *
       // ************************************
       Runnable captureImage = new Runnable() {
           public void run() {
              bimg=getImage();
              if(bimg!=null) {
                 ...
                 // do something...
                 ...
            
              }
 
          }
        };
        Thread t=new Thread(captureImage);
        t.start();
    }
    
    
My "do something..." in the invokeGetImage() take a
milisecond or so to complete. You may have to wait for 
similar duration (or explicitly set flag to indicate the
thread had finished) before you try to access the reference
(ie. bimg) BufferedImage, after you have executed 
invokeGetImage().
  
Best of luck.
  
  
Ng Say Teong.


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