Printing in Java

Paul Hsieh pahsieh at usgs.gov
Sat Aug 28 02:05:15 EDT 1999


Mykola: 

Printing vtkPanel is not easily done because vtkPanel is
actually rendered on the native side. As you noticed, the paint
method of vtkPanel does not use Graphics. Thus, the
print implementation of Java doesn't do any good.

You could save the vtk window image to various graphical file formats.
For example, vtkRenderWindow has a method called WritePPMImageFile. 
Also, you can save the vtk window image to a bitmap by the following 
chain of filters

vtkRenderWindow --> vtkWindowToImageFilter --> vtkBMPWriter

If you write you own code to print the vtk window, it
will likely have to be platform specific and invlove
some Java Native Interface (JNI) programming. For example, if
you are working in Windows, you might write a JNI function
to do the following (I have not tried this, but I think
this might work):

1. Tell the render window to render to memory (invoke
   the SetupMemoryRendering method)

2. Render the image (invoke the Render method).

3. Get the image data from memory (invoke GetMemoryData method).
   The data are 24 bit rgb color values. These are basically
   data for a device independent bitmap (DIB).

4. Convert the data into a jint array that can be passed back to
   the Java side to be interpreted as an int array.

Back on the Java side, create Image from the int array using 
the MemoryImageSource class. Now that you have an Image,
you can get a Graphics from the PrintJob and invoke drawImage.

Good luck.
Paul

Mykola Khotyaintsev wrote:
> 
> Dear VTK-users,
> 
> I have problems with printing vtkPanel.
> I use renPanel.printAll(printerJob.getGraphics()) (or print instead of
> printAll) to print, but get rectangle or nothing.
> 
> I think that Container.printAll(Graphics g) makes all components print
> themself to g may be using paint(Graphics g) metod of each component. In
> my case they are printed to g wich belongs to printer.
> 
> But vtkPanel's paint(Graphics g) method is:
> 
> public void paint(Graphics g)
>   {
>   this.Render();
>   }
> 
> And it doesn't care about g changes.
>


-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------





More information about the vtkusers mailing list