Package breadboards
Class GImage
- java.lang.Object
-
- breadboards.GObject
-
- breadboards.GImage
-
-
Constructor Summary
Constructors Constructor Description GImage(int[][] pixels)
constructs a GImage using the specified 2d array of (integer) pixel informationGImage(java.awt.image.BufferedImage image)
constructs a GImage using the specified imageGImage(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 GImagestatic int
createRGBPixel(int red, int green, int blue)
encapsulates the red, green, and blue components of a color into a single int valuestatic 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 valuevoid
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 transparencystatic int
getBlue(int pixel)
returns the blue component associated with the specified integer valueGRectangle
getBounds()
returns the bounding rectangle for this GImagestatic 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 valueint
getHeight()
returns height of GImage objectjava.awt.image.BufferedImage
getImage()
returns the image associated with this GImageint[][]
getPixelArray()
returns a 2d array of integer values corresponding to the colors of the pixels of this imagestatic int
getRed(int pixel)
returns the red component associated with the specified integer valueint
getWidth()
returns width of GImage objectvoid
saveImage(java.io.File file)
saves the image associated with this GImage using the specified file objectvoid
saveImage(java.lang.String filename)
saves the image associated with this GImage using the filename (and path) givenvoid
setImage(java.awt.image.BufferedImage image)
reset the image of the GImage to a given (BufferedImage) imagevoid
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 breadboards.GObject
addMouseListener, addMouseMotionListener, getBreadboard, getLocation, getMouseListeners, getMouseMotionListeners, getParent, getX, getY, isVisible, move, movePolar, removeMouseListener, removeMouseMotionListener, sendBackward, sendForward, sendToBack, sendToFront, setLocation, setParent, setVisible, setX, setY, updateBreadboard
-
-
-
-
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 imagex
- the x-coordinate of the location specifiedy
- 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 packagecls
- 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
-
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
-
-