Class Image


public class Image extends DrawableElement
Draw an image on top of the canvas
  • Constructor Details

    • Image

      public Image(String filename, int x, int y, int width, int height)
    • Image

      public Image(String filename, int x, int y)
    • Image

      public Image(int x, int y, int width, int height)
      Creates a new empty image that you can add content to through the getGraphicsContext().
      Parameters:
      x - position of the image x.
      y - position of the image y.
      width - width of the image.
      height - height of the image.
    • Image

      public Image(int width, int height)
  • Method Details

    • getFilename

      public String getFilename()
    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • getGraphicsContext

      public Graphics2D getGraphicsContext()
    • setFilename

      public void setFilename(String filename)
    • createSubImage

      public Image createSubImage(String originFileName, String newName, int x, int y, int width, int height)
      Take part of another image to create a new one. Afterward you need to set the position and size to actually place the new image. Please note, you only need to do this once, then you can simply create an image using the new name.
      Parameters:
      originFileName - name of the original image.
      newName - name of the sub-image.
      x - position of the sub-image x
      y - position of the sub-image y
      width - width of the sub-image
      height - height of the sub-image
      Returns:
      a new Image that is a section of a larger original image.
    • setWidth

      public void setWidth(int width)
    • setHeight

      public void setHeight(int height)
    • draw

      public void draw(Graphics2D g)
      Specified by:
      draw in class CanvasElement