Class Pixel
java.lang.Object
Pixel
Class that references a pixel in a picture. A pixel has an x and y
location in a picture. A pixel knows how to get and set the red,
green, blue, and alpha values in the picture. A pixel also knows
how to get and set the color using a Color object.
Copyright Georgia Institute of Technology 2004
-
Constructor Summary
ConstructorsConstructorDescriptionPixel(DigitalPicture picture, int x, int y) A constructor that take the x and y location for the pixel and the picture the pixel is coming from -
Method Summary
Modifier and TypeMethodDescriptiondoublecolorDistance(Color testColor) Method to get the distance between this pixel's color and the passed colorstatic doublecolorDistance(Color color1, Color color2) Method to compute the color distances between two color objectsintgetAlpha()Method to get the amount of alpha (transparency) at this pixel.doubleMethod to get the average of the colors of this pixelintgetBlue()Method to get the amount of blue at this pixel.static intgetBlue(int value) Method to get the blue value from a pixel represented as an intgetColor()Method to get a color object that represents the color at this pixel.intgetGreen()Method to get the amount of green at this pixel.static intgetGreen(int value) Method to get the green value from a pixel represented as an intintgetRed()Method to get the amount of red at this pixel.static intgetRed(int value) Method to get the red value from a pixel represented as an intintgetX()Method to get the x location of this pixel.intgetY()Method to get the y location of this pixel.voidsetAlpha(int value) Method to set the alpha (transparency) to a new alpha valuevoidsetBlue(int value) Method to set the blue to a new blue valuevoidMethod to set the pixel color to the passed in color object.voidsetGreen(int value) Method to set the green to a new green valuevoidsetRed(int value) Method to set the red to a new red valuetoString()Method to return a string with information about this pixelvoidupdatePicture(int alpha, int red, int green, int blue) Method to update the picture based on the passed color values for this pixel
-
Constructor Details
-
Pixel
A constructor that take the x and y location for the pixel and the picture the pixel is coming from- Parameters:
picture- the picture that the pixel is inx- the x location of the pixel in the picturey- the y location of the pixel in the picture
-
-
Method Details
-
getX
public int getX()Method to get the x location of this pixel.- Returns:
- the x location of the pixel in the picture
-
getY
public int getY()Method to get the y location of this pixel.- Returns:
- the y location of the pixel in the picture
-
getAlpha
public int getAlpha()Method to get the amount of alpha (transparency) at this pixel. It will be from 0-255.- Returns:
- the amount of alpha (transparency)
-
getRed
public int getRed()Method to get the amount of red at this pixel. It will be from 0-255 with 0 being no red and 255 being as much red as you can have.- Returns:
- the amount of red from 0 for none to 255 for max
-
getRed
public static int getRed(int value) Method to get the red value from a pixel represented as an int- Parameters:
value- the color value as an int- Returns:
- the amount of red
-
getGreen
public int getGreen()Method to get the amount of green at this pixel. It will be from 0-255 with 0 being no green and 255 being as much green as you can have.- Returns:
- the amount of green from 0 for none to 255 for max
-
getGreen
public static int getGreen(int value) Method to get the green value from a pixel represented as an int- Parameters:
value- the color value as an int- Returns:
- the amount of green
-
getBlue
public int getBlue()Method to get the amount of blue at this pixel. It will be from 0-255 with 0 being no blue and 255 being as much blue as you can have.- Returns:
- the amount of blue from 0 for none to 255 for max
-
getBlue
public static int getBlue(int value) Method to get the blue value from a pixel represented as an int- Parameters:
value- the color value as an int- Returns:
- the amount of blue
-
getColor
Method to get a color object that represents the color at this pixel.- Returns:
- a color object that represents the pixel color
-
setColor
Method to set the pixel color to the passed in color object.- Parameters:
newColor- the new color to use
-
updatePicture
public void updatePicture(int alpha, int red, int green, int blue) Method to update the picture based on the passed color values for this pixel- Parameters:
alpha- the alpha (transparency) at this pixelred- the red value for the color at this pixelgreen- the green value for the color at this pixelblue- the blue value for the color at this pixel
-
setRed
public void setRed(int value) Method to set the red to a new red value- Parameters:
value- the new value to use
-
setGreen
public void setGreen(int value) Method to set the green to a new green value- Parameters:
value- the value to use
-
setBlue
public void setBlue(int value) Method to set the blue to a new blue value- Parameters:
value- the new value to use
-
setAlpha
public void setAlpha(int value) Method to set the alpha (transparency) to a new alpha value- Parameters:
value- the new value to use
-
colorDistance
Method to get the distance between this pixel's color and the passed color- Parameters:
testColor- the color to compare to- Returns:
- the distance between this pixel's color and the passed color
-
colorDistance
-
getAverage
public double getAverage()Method to get the average of the colors of this pixel- Returns:
- the average of the red, green, and blue values
-
toString
-