Class Overlay

java.lang.Object
org.loboevolution.img.Overlay
Direct Known Subclasses:
PixelMarkerOverlay

public abstract class Overlay extends Object
An overlay is a layer on top of an image. It can be used to add annotations, arbitrary shapes to an image. Drawing is implemented in the paint method.

The following is an implementation of a simple example overlay that draws a cross over the image:


 class XPainter extends Overlay {
        public void paint(Graphics2D g, BufferedImage image, AffineTransform transform) {
                g.setColor(Color.RED);
                double[] bounds = { 0, 0, image.getWidth(), 0, image.getWidth(), image.getHeight(), 0, image.getHeight() };
                transform.transform(bounds, 0, bounds, 0, 4);
                g.drawLine((int) bounds[0], (int) bounds[1], (int) bounds[4], (int) bounds[5]);
                g.drawLine((int) bounds[2], (int) bounds[3], (int) bounds[6], (int) bounds[7]);
        }
 }
 
It can be added to a viewer by calling viewer.addOverlay(new XPainter(), 10). Author Kazo Csaba
  • Constructor Details

    • Overlay

      public Overlay()
  • Method Details

    • addOverlayComponent

      public final void addOverlayComponent(OverlayComponent c)

      addOverlayComponent.

      Parameters:
      c - a OverlayComponent object.
    • removeOverlayComponent

      public final void removeOverlayComponent(OverlayComponent c)

      removeOverlayComponent.

      Parameters:
      c - a OverlayComponent object.
    • repaint

      public void repaint()
      Causes the overlay to be repainted.
    • paint

      public abstract void paint(Graphics2D g, BufferedImage image, AffineTransform transform)
      Called to paint the contents of this overlay. The graphics context to paint on is a copy for this overlay and can be freely modified.

      The method receives the currently displayed image. The image is never null - if there is currently no image being displayed in the image viewer, then the paint method is not called.

      This method also receives the transformation that is applied to the image before it is displayed. This transformation is most commonly the concatenation of a uniform scale and a translation. The original image bounds (0, 0) - (image.getWidth(), image.getHeight()) are mapped using this transformation to get the final display bounds. The overlay should not rely on whether painting outside these final bounds will be visible or not.

      Parameters:
      g - the graphics context to draw onto
      image - the current image
      transform - the transformation applied to the image before displaying