[vtkusers] Need help getting vtkCanvas as Image via swing or AWT

Alan alan at vuesonix.com
Tue Apr 22 16:40:48 EDT 2003

I'm trying to capture the image output of the vtkCanvas component.  I've 

//    should capture image contents from swing based component
       img=rpMgr.getOffscreenBuffer(panel, panel.getWidth(), 

and also

//    should capture image contents from awt based component
       Component c=panel.getvtkCanvas();
       img=c.createImage(c.getWidth(), c.getHeight());
       Graphics g=img.getGraphics();

panel extends Jpanel and contains a vtkCanvas() object.

Although the image size is always correct, the image contents are always 
empty.  This despite the fact that VTK has displayed a pretty picture 
onscreen, Java just doesn't seem to be able to access it at either the 
Swing or AWT level.

Can anyone help me capture the output of vtkCanvas to an Image()?  Is 
there a reason that this can't be done?

Thanks for any insight on this puzzle.

BTW, my workaround has been to capture the component via the Robot() class:

         Robot r=new Robot();
         Rectangle rect=panel.getBounds();

This works acceptably, but only if the vtkCanvas is not covered by any 
other windows.

More information about the vtkusers mailing list