Class ImagePortrayal2D

All Implemented Interfaces:
Serializable, Portrayal, Portrayal2D

public class ImagePortrayal2D extends RectanglePortrayal2D
A simple portrayal for 2D visualization of images. It extends the SimplePortrayal2D and it manages the drawing and hit-testing for rectangular shapes containing images/pictures.

ImagePortrayal2D draws an image centered on the Portrayal's origin. Images are not stretched to fill the info.draw.height x info.draw.width rectangle. Instead, if the image is taller than it is wide, then the width of the image will be info.draw.width * scale and the height will stay in proportion; else the height of the image will be info.draw.height * scale and the width will stay in proportion.

See Also:
  • Field Details

    • image

      public Image image
  • Constructor Details

    • ImagePortrayal2D

      public ImagePortrayal2D(ImageIcon icon, double scale)
      Creates an ImagePortrayal2D with the image inside the given ImageIcon, and scaled with the given scale.
    • ImagePortrayal2D

      public ImagePortrayal2D(ImageIcon icon)
      Creates an ImagePortrayal2D with the image inside the given ImageIcon.
    • ImagePortrayal2D

      public ImagePortrayal2D(Class c, String resourceName, double scale)
      Creates an ImagePortrayal2D by loading an Image resource using getClass().getResource(), and scaled with the given scale.
    • ImagePortrayal2D

      public ImagePortrayal2D(Class c, String resourceName)
      Creates an ImagePortrayal2D by loading an Image resource using getClass().getResource()
    • ImagePortrayal2D

      public ImagePortrayal2D(Image image)
      Creates an ImagePortrayal2D with the given image.
    • ImagePortrayal2D

      public ImagePortrayal2D(Image image, double scale)
      Creates an ImagePortrayal2D with the given image, and scaled with the given scale..
  • Method Details

    • draw

      public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
      Description copied from interface: Portrayal2D
      Draw a the given object with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels. The rectangle given by info.clip specifies the only region in which it is necessary to draw. If info.precise is true, try to draw using real-valued high-resolution drawing rather than faster integer drawing. It is possible that object is null. The location of the object in the field may (and may not) be stored in info.location. The form of that location varies depending on the kind of field used.
      Specified by:
      draw in interface Portrayal2D
      Overrides:
      draw in class RectanglePortrayal2D