Package breadboards

Class GImage

  • All Implemented Interfaces:
    Drawable
    Direct Known Subclasses:
    GDieImage

    public class GImage
    extends GObject
    Subclass of GObject used for displaying a image
    Author:
    paul oser
    • Constructor Summary

      Constructors 
      Constructor Description
      GImage​(int[][] pixels)
      constructs a GImage using the specified 2d array of (integer) pixel information
      GImage​(java.awt.image.BufferedImage image)
      constructs a GImage using the specified image
      GImage​(java.awt.image.BufferedImage image, double x, double y)
      constructs a GImage using the specified image at the specified location (x,y)
      GImage​(java.lang.String filename)
      constructs a GImage based on the image identified by the given filename (and path)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(double x, double y)
      returns true when (x,y) is inside the bounding rectangle for this GImage
      static int createRGBPixel​(int red, int green, int blue)
      encapsulates the red, green, and blue components of a color into a single int value
      static int createRGBPixel​(int red, int green, int blue, int alpha)
      encapsulates the red, green, and blue components of a color and a level of transparency into a single integer value
      void draw​(java.awt.Graphics g)
      draws the GImage (generally not called directly)
      static int getAlpha​(int pixel)
      returns the level of transparency associated with an integer value representing a color with transparency
      static int getBlue​(int pixel)
      returns the blue component associated with the specified integer value
      GRectangle getBounds()
      returns the bounding rectangle for this GImage
      static GImage getFromResource​(java.lang.String resourceFileName, java.lang.Class cls)
      returns a GImage from a resource file (i.e., a .jpg or .png image file in a java package)
      static int getGreen​(int pixel)
      returns the green component associated with the specified integer value
      int getHeight()
      returns height of GImage object
      java.awt.image.BufferedImage getImage()
      returns the image associated with this GImage
      int[][] getPixelArray()
      returns a 2d array of integer values corresponding to the colors of the pixels of this image
      static int getRed​(int pixel)
      returns the red component associated with the specified integer value
      int getWidth()
      returns width of GImage object
      void saveImage​(java.io.File file)
      saves the image associated with this GImage using the specified file object
      void saveImage​(java.lang.String filename)
      saves the image associated with this GImage using the filename (and path) given
      void setImage​(java.awt.image.BufferedImage image)
      reset the image of the GImage to a given (BufferedImage) image
      void setImage​(java.lang.String filename)
      reset the image of the GImage to the one identified by the given filename (and path)
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GImage

        public GImage​(java.awt.image.BufferedImage image)
        constructs a GImage using the specified image
        Parameters:
        image - the specified image
      • GImage

        public GImage​(java.awt.image.BufferedImage image,
                      double x,
                      double y)
        constructs a GImage using the specified image at the specified location (x,y)
        Parameters:
        image - the specified image
        x - the x-coordinate of the location specified
        y - the y-coordiante of the location specified
      • GImage

        public GImage​(int[][] pixels)
        constructs a GImage using the specified 2d array of (integer) pixel information
        Parameters:
        pixels - the specified 2d array of (integer) pixel information
      • GImage

        public GImage​(java.lang.String filename)
        constructs a GImage based on the image identified by the given filename (and path)
        Parameters:
        filename - the file containing the image to be used
    • Method Detail

      • getFromResource

        public static GImage getFromResource​(java.lang.String resourceFileName,
                                             java.lang.Class cls)
        returns a GImage from a resource file (i.e., a .jpg or .png image file in a java package)
        Parameters:
        resourceFileName - the name of the image file in your package
        cls - the associated class
        Returns:
        a GImage that looks like the image file in question
      • setImage

        public void setImage​(java.lang.String filename)
        reset the image of the GImage to the one identified by the given filename (and path)
        Parameters:
        filename - the file containing the image to be used
      • setImage

        public void setImage​(java.awt.image.BufferedImage image)
        reset the image of the GImage to a given (BufferedImage) image
        Parameters:
        image - the image to be used as the new GImage image
      • saveImage

        public void saveImage​(java.lang.String filename)
        saves the image associated with this GImage using the filename (and path) given
        Parameters:
        filename - the name of the file (and path) to be used when saving the image
      • saveImage

        public void saveImage​(java.io.File file)
        saves the image associated with this GImage using the specified file object
        Parameters:
        file - the specified file object
      • createRGBPixel

        public static int createRGBPixel​(int red,
                                         int green,
                                         int blue)
        encapsulates the red, green, and blue components of a color into a single int value
        Parameters:
        red - the amount of red in the color (on a scale from 0 to 255)
        green - the amount of green in the color (on a scale from 0 to 255)
        blue - the amount of blue in the color (on a scale from 0 to 255)
        Returns:
        a single int value encapsulating the red, green, and blue components of a color
      • createRGBPixel

        public static int createRGBPixel​(int red,
                                         int green,
                                         int blue,
                                         int alpha)
        encapsulates the red, green, and blue components of a color and a level of transparency into a single integer value
        Parameters:
        red - the amount of red in the color (on a scale from 0 to 255)
        green - the amount of green in the color (on a scale from 0 to 255)
        blue - the amount of blue in the color (on a scale from 0 to 255)
        alpha - the level of transparency (on a scale from 0 to 255)
        Returns:
        a single int value encapsulating the red, green, and blue components of a color and a level of transparency
      • getAlpha

        public static int getAlpha​(int pixel)
        returns the level of transparency associated with an integer value representing a color with transparency
        Parameters:
        pixel - - the integer value representing a color with transparency
        Returns:
        - the level of transparency (0-255)
      • getRed

        public static int getRed​(int pixel)
        returns the red component associated with the specified integer value
        Parameters:
        pixel - - the integer value representing a color with transparency
        Returns:
        the red component of the color (0-255)
      • getGreen

        public static int getGreen​(int pixel)
        returns the green component associated with the specified integer value
        Parameters:
        pixel - - the integer value representing a color with transparency
        Returns:
        the green component of the color (0-255)
      • getBlue

        public static int getBlue​(int pixel)
        returns the blue component associated with the specified integer value
        Parameters:
        pixel - - the integer value representing a color with transparency
        Returns:
        the blue component of the color (0-255)
      • getPixelArray

        public int[][] getPixelArray()
        returns a 2d array of integer values corresponding to the colors of the pixels of this image
        Returns:
        a 2d array of integer values corresponding to the colors of the pixels of this image
      • getImage

        public java.awt.image.BufferedImage getImage()
        returns the image associated with this GImage
        Returns:
        the image associated with this GImage
      • draw

        public void draw​(java.awt.Graphics g)
        draws the GImage (generally not called directly)
      • contains

        public boolean contains​(double x,
                                double y)
        returns true when (x,y) is inside the bounding rectangle for this GImage
        Specified by:
        contains in class GObject
        Parameters:
        x - x-coordinate of the point in question
        y - y-coordinate of the point in question
        Returns:
        true if the point is contained in the GObject, false otherwise
      • getHeight

        public int getHeight()
        returns height of GImage object
        Returns:
        the height of the GImage object
      • getWidth

        public int getWidth()
        returns width of GImage object
        Returns:
        the width of the GImage object
      • getBounds

        public GRectangle getBounds()
        returns the bounding rectangle for this GImage
        Specified by:
        getBounds in class GObject
        Returns:
        the bounding rectangle of the GObject