Class GImage

  • All Implemented Interfaces:
    java.awt.Paint, java.awt.Transparency, java.lang.Cloneable

    public class GImage
    extends GraphicE
    implements java.awt.Paint
    Wraps a BufferedImage into a GraphicE object
    • Field Summary

      • Fields inherited from interface java.awt.Transparency

        BITMASK, OPAQUE, TRANSLUCENT
    • Constructor Summary

      Constructors 
      Constructor Description
      GImage​(int x, int y, java.awt.image.BufferedImage img)
      Create a new GImage from a given BufferedImage
      GImage​(int x, int y, java.io.File file)
      Create a new GImage from a given file
      GImage​(GImage e)
      Copy constructor
      GImage​(java.io.File file)
      Create a new GImage from a given file
      GImage​(java.lang.String path)
      Create a new GImage from a given path
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      GImage clone()  
      java.awt.PaintContext createContext​(java.awt.image.ColorModel cm, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, java.awt.RenderingHints hints)  
      void draw​(java.awt.Graphics2D g)
      Draws the component on the given graphics
      boolean equals​(java.lang.Object obj)  
      int getHeight()
      Retrieves the current height of the GImage in pixels
      int getOriginalHeight()
      Retrieves the original height of the GImage in pixels
      int getOriginalWidth()
      Retrieves the original width of the GImage in pixels
      int getTransparency()  
      int getWidth()
      Retrieves the current width of the GImage in pixels
      int hashCode()  
      void move​(int x, int y)
      Moves the center of the image to the given coordinates
      void scale​(double scale)
      Symmetrically scales an image.
      If scale is less than 1 then the image will be reduced.
      void scale​(double sx, double sy)
      Scales an image.
      void traslate​(int x, int y)
      Traslates this element on X and Y
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GImage

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

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

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

        public GImage​(int x,
                      int y,
                      java.io.File file)
               throws java.io.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:
        java.io.IOException - if something goes wrong when opening or reading the image file.
      • GImage

        public GImage​(int x,
                      int y,
                      java.awt.image.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 Detail

      • 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 refer to the original image.
        Parameters:
        sx - Horizontal scale
        sy - Vertical scale
        See Also:
        getOriginalHeight(), ()
      • 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​(java.awt.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
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class GraphicE
      • createContext

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

        public int getTransparency()
        Specified by:
        getTransparency in interface java.awt.Transparency