Class GImage

java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.GImage
All Implemented Interfaces:
Paint, Transparency, Cloneable

public class GImage extends GraphicE implements Paint
Wraps a BufferedImage into a GraphicE object
Author:
Federico Vera <[email protected]>
  • Constructor Details

    • GImage

      public GImage(GImage e)
      Copy constructor
      Parameters:
      e - GImage to copy
      Throws:
      IllegalArgumentException - if e is null
    • GImage

      public GImage(String path) throws IOException
      Create a new GImage from a given path
      Parameters:
      path - path to the image
      Throws:
      IOException - if something goes wrong when opening or reading the image file.
    • GImage

      public GImage(File file) throws IOException
      Create a new GImage from a given file
      Parameters:
      file - file of the image
      Throws:
      IOException - if something goes wrong when opening or reading the image file.
    • GImage

      public GImage(int x, int y, File file) throws IOException
      Create a new GImage from a given file
      Parameters:
      x - X coordinate of the center of the image
      y - Y coordinate of the center of the image
      file - file of the image
      Throws:
      IOException - if something goes wrong when opening or reading the image file.
    • GImage

      public GImage(int x, int y, BufferedImage img)
      Create a new GImage from a given BufferedImage
      Parameters:
      x - X coordinate of the center of the image
      y - Y coordinate of the center of the image
      img - image to wrap
  • Method Details

    • getWidth

      public final int getWidth()
      Retrieves the current width of the GImage in pixels
      Returns:
      width in px
    • getHeight

      public final int getHeight()
      Retrieves the current height of the GImage in pixels
      Returns:
      height in px
    • getOriginalWidth

      public final int getOriginalWidth()
      Retrieves the original width of the GImage in pixels
      Returns:
      width in px
    • getOriginalHeight

      public final int getOriginalHeight()
      Retrieves the original height of the GImage in pixels
      Returns:
      height in px
    • scale

      public void scale(double scale)
      Symmetrically scales an image.
      • If scale is less than 1 then the image will be reduced.
      • If scale is 1, then nothing noticeable should happen to the image.
      • If scale is more than 1 then the image will be bigger.
      Parameters:
      scale - scale quotient
    • scale

      public void scale(double sx, double sy)
      Scales an image.
      • If scaleX/Y is less than 1 then the image will be reduced.
      • If scaleX/Y is 1, then nothing noticeable should happen to the image.
      • If scaleX/Y is more than 1 then the image will be bigger.
      Note: Scaling is not accumulative, it always refers to the original image.
      Parameters:
      sx - Horizontal scale
      sy - Vertical scale
      See Also:
    • traslate

      public void traslate(int x, int y)
      Description copied from class: GraphicE
      Traslates this element on X and Y
      Specified by:
      traslate in class GraphicE
      Parameters:
      x - size in px of the horizontal translation
      y - size in px of the vertical translation
    • move

      public void move(int x, int y)
      Moves the center of the image to the given coordinates
      Parameters:
      x - new X coordinate of the center of the image
      y - new Y coordinate of the center of the image
    • draw

      public void draw(Graphics2D g)
      Description copied from class: GraphicE
      Draws the component on the given graphics
      Specified by:
      draw in class GraphicE
      Parameters:
      g - where to draw
    • clone

      public GImage clone()
      Specified by:
      clone in class GraphicE
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GraphicE
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class GraphicE
    • createContext

      public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
      Specified by:
      createContext in interface Paint
    • getTransparency

      public int getTransparency()
      Specified by:
      getTransparency in interface Transparency