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

Alan alan at vuesonix.com
Wed Apr 23 13:12:33 EDT 2003


Christopher M. Navarro wrote:

>
>On Tue, 22 Apr 2003, Alan wrote:
>
>  
>
>>Hi,
>>I'm trying to capture the image output of the vtkCanvas component.  I've 
>>tried
>>
>>
>>//    should capture image contents from swing based component
>>       RepaintManager 
>>rpMgr=RepaintManager.currentManager(panel.getvtkCanvas());
>>       img=rpMgr.getOffscreenBuffer(panel, panel.getWidth(), 
>>panel.getHeight());
>>
>>
>>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();
>>       c.printAll(g);
>>
>>
>>where
>>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.
>>   --Alan
>>
>>
>>BTW, my workaround has been to capture the component via the Robot() class:
>>
>>         Robot r=new Robot();
>>         Rectangle rect=panel.getBounds();
>>         rect.translate(-panel.getInsets().left,-panel.getInsets().top);
>>         img=r.createScreenCapture(rect);
>>
>>
>>This works acceptably, but only if the vtkCanvas is not covered by any 
>>other windows.
>>    
>>
>
>If you are using the vtkCanvas supplied with the latest release (which I 
>assume you are), you can do the following:
>
>vtkRendererSource renSrc = new vtkRendererSource();
>renSrc.SetInput(myVtkCanvas.GetRenderer());
>renSrc.WholeWindowOn();
>
>vtkPNGWriter writer = new vtkPNGWriter();
>writer.SetInput(renSrc.GetOutput());
>writer.SetFileName("test");
>writer.Write();
>
>vtkPNGWriter can be replaced by any of the other image writers such as 
>vtkJPEGWriter, etc.  
>
>HTH,
>
>chris
>
>
>  
>
Hi Chris,
Thanks much for your response.  I will use the various writers to store 
my images on disk as you suggest.  Unfortunately, I still also
need to save my renderings in memory as an Image for other purposes (eg, 
animation).  Any other thoughts?
  --Alan




More information about the vtkusers mailing list