import vtk.vtkActor;
import vtk.vtkNamedColors;
import vtk.vtkNativeLibrary;
import vtk.vtkPolyDataMapper;
import vtk.vtkRenderWindow;
import vtk.vtkRenderWindowInteractor;
import vtk.vtkRenderer;
import vtk.vtkSphereSource;
import vtk.vtkPNGWriter;
import vtk.vtkWindowToImageFilter;

public class Screenshot 
{
  // -----------------------------------------------------------------
  // Load VTK library and print which library was not properly loaded
  static 
  {
    if (!vtkNativeLibrary.LoadAllNativeLibraries()) 
    {
      for (vtkNativeLibrary lib : vtkNativeLibrary.values()) 
      {
        if (!lib.IsLoaded()) 
        {
          System.out.println(lib.GetLibraryName() + " not loaded");
        }
      }
    }
    vtkNativeLibrary.DisableOutputWindow(null);
  }
  // -----------------------------------------------------------------

  public static void main(String args[]) 
  {
    //parse command line arguments
    if (args.length != 1) 
    {
      System.err.println("Usage: java -classpath ... Filename(.png) e.g screenshot.png");
      return;
    }
    String fileName = args[0];
    
    vtkNamedColors colors = new vtkNamedColors();

    //Renderer Background Color
    double Bgcolor[] = new double[4];

    colors.GetColor("White", Bgcolor);
   
    vtkSphereSource sphereSource = new vtkSphereSource();
    sphereSource.SetCenter(0.0, 0.0, 0.0 );
    sphereSource.SetRadius(4.0);
    sphereSource.Update();
    
    vtkPolyDataMapper sphereMapper  = new vtkPolyDataMapper();
    sphereMapper.SetInputData (sphereSource.GetOutput());
    
    vtkActor sphereActor = new vtkActor();
    sphereActor.SetMapper(sphereMapper);
	
    // Create the renderer, render window and interactor.
    vtkRenderer ren = new vtkRenderer();
    vtkRenderWindow renWin = new vtkRenderWindow();
    renWin.AddRenderer(ren);
    renWin.SetAlphaBitPlanes(1);
    vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
    iren.SetRenderWindow(renWin);
    
    // Visualise
    ren.AddActor(sphereActor);
    ren.SetBackground(Bgcolor);
    
    renWin.SetSize(300, 300);
    renWin.Render();
    
    vtkWindowToImageFilter windowToImageFilter = new vtkWindowToImageFilter();
    windowToImageFilter.SetInput(renWin);
    windowToImageFilter.SetScale(2);
    windowToImageFilter.SetInputBufferTypeToRGB();

    windowToImageFilter.ReadFrontBufferOff();
    windowToImageFilter.Update();

    vtkPNGWriter writer = new vtkPNGWriter();
    writer.SetFileName(fileName);
    writer.SetInputConnection(windowToImageFilter.GetOutputPort());
    writer.Write();
    
    renWin.Render();
    ren.ResetCamera();
    renWin.Render();
    iren.Start();
  }
}

@@ -844,16 +844,549 @@
 --------
+%0A  %0A  public static void writeImage(vtkRenderWindow renWin, String fn) %0A  %7B %0A    vtkWindowToImageFilter windowToImageFilter = new vtkWindowToImageFilter();%0A    windowToImageFilter.SetInput(renWin);%0A    windowToImageFilter.SetScale(1);%0A    windowToImageFilter.SetInputBufferTypeToRGB();%0A%0A    windowToImageFilter.ReadFrontBufferOff();%0A    windowToImageFilter.Update();%0A%0A    vtkPNGWriter writer = new vtkPNGWriter();%0A    writer.SetFileName(fn);%0A    writer.SetInputConnection(windowToImageFilter.GetOutputPort());%0A    writer.Write();%0A  %7D
 %0A%0A  publ
@@ -1803,16 +1803,17 @@
 or);%0A   
+ 
 %0A    vtk
@@ -2649,535 +2649,67 @@
 %0A   
- 
 %0A    
-vtkWindowToImageFilter windowToImageFilter = new vtkWindowToImageFilter();%0A    windowToImageFilter.SetInput(renWin);%0A    windowToImageFilter.SetScale(2);%0A    windowToImageFilter.SetInputBufferTypeToRGB();%0A%0A    windowToImageFilter.ReadFrontBufferOff();%0A    windowToImageFilter.Update(
+writeImage(renWin, fileName
 );%0A
-%0A
     
-vtkPNGWriter writer = new vtkPNGWriter();%0A    writer.SetFileName(fileName);%0A    writer.SetInputConnection(windowToImageFilter.GetOutputPort());%0A    writer.Write();%0A    %0A    renWin.Render();%0A    ren.ResetCamera();%0A    renWin.Render
+%0A    iren.Initialize
 ();%0A

Update Screenshot.java