Skip to content

ReadBMP

vtk-examples/Java/IO/ReadBMP

Description

vtkBMPReader is a source object that reads Windows BMP files. This includes indexed and 24 bit bitmaps Usually, all BMPs are converted to 24 bit RGB, but BMPs may be output as 8 bit images with a LookupTable if they allow 8 bit BMP flag is set.

BMPReader creates structured point datasets. The dimension of the dataset depends upon the number of files read. Reading a single file results in a 2D image, while reading more than one file results in a 3D volume.

Other languages

See (Cxx), (CSharp)

Question

If you have a question about this example, please use the VTK Discourse Forum

Code

ReadBMP.java

import vtk.vtkNativeLibrary;
import vtk.vtkRenderWindowInteractor;
import vtk.vtkImageViewer2;
import vtk.vtkBMPReader;


public class ReadBMP 
{
  // -----------------------------------------------------------------
  // 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(.bmp) e.g masonry.bmp");
      return;
    }
    String inputFilename = args[0];

    vtkBMPReader reader = new vtkBMPReader();
    reader.SetFileName(inputFilename);
    reader.Update();

    // Visualize
    vtkImageViewer2 imageViewer = new vtkImageViewer2();
    imageViewer.SetInputConnection(reader.GetOutputPort());
    vtkRenderWindowInteractor renderWindowInteractor =new vtkRenderWindowInteractor();
    imageViewer.SetupInteractor(renderWindowInteractor);
    imageViewer.Render();
    imageViewer.GetRenderer().ResetCamera();
    imageViewer.Render();

    renderWindowInteractor.Start();

   }
}