Site logo, www.grelf.net
 

Minimal GRIP application

Every ImFrame has its own menu bar from which much of the functionality of GRIP is available. So a minimal application using GRIP.jar would simply construct an ImFrame from an image file. The constructor displays the image in the frame.


package net.grelf.app;

import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import net.grelf.grip.DefaultMeasurementHandler;
import net.grelf.grip.ImFrame;

/** Minimal application using GRIP.jar */
public class App implements Runnable
{
  public static void main (String... args)
  {
    try
    {
      SwingUtilities.invokeAndWait (new App ());
    }
    catch (InterruptedException ex)
    {
      Logger.getLogger (App.class.getName()).log (Level.SEVERE, null, ex);
    }
    catch (InvocationTargetException ex)
    {
      Logger.getLogger (App.class.getName()).log (Level.SEVERE, null, ex);
    }
  } // main

  public void run ()
  {
    ImFrame frame = new ImFrame ("testimage.jpg", new DefaultMeasurementHandler ());
	
    // Then you can either do image processing calling methods of the frame (see APIdocs)
    // in which case the result will be displayed:
    frame.invert ();

    // Or you can get hold of the image and process it without the result being seen:
    Image image = frame.getImPane ().getImage ();
    image.invert ();

    // And you can find out everything about the image, such as:
    int bitDepth = image.getBitsPerChannel ();
    RangeInt [] ranges = image.getChannelRanges ();
    Metadata metadata = image.getMetadata ();
    Calibration calibration = image.getCalibration ();
    // etc...

  } // run

} // App
		

Just remember two things:

Next page