public class Pixel
extends java.lang.Object
Pixel
class represents a color as its component values of
red, green, blue, as well as alpha (for transparency).
Each of the component values of a pixel must have a value between 0 and 255. If a value is given outside that range, it is changed to be within that range. As such, a negative value would be set to 0 and a value greater than 255 would be set to 255.
Example usage:
ImageResource image = new ImageResource(); for (Pixel p : image.pixels()) { int red = p.getRed(); int green = p.getGreen(); int blue = p.getBlue(); int average = (red + green + blue) / 3; p.setRed(average); p.setGreen(average); p.setBlue(average); } image.draw();
This is open-source software released under the terms of the GPL (http://www.gnu.org/licenses/gpl.html).
Constructor and Description |
---|
Pixel(Pixel other)
Creates a new Pixel from with the same values as the other pixel passed
as a parameter.
|
Modifier and Type | Method and Description |
---|---|
int |
getAlpha()
Returns the value of the pixel's alpha (or transparency) component.
|
int |
getBlue()
Returns the value of the pixel's blue component.
|
int |
getGreen()
Returns the value of the pixel's green component.
|
int |
getRed()
Returns the value of the pixel's red component.
|
int |
getX()
Returns the pixel's x-coordinate within the image.
|
int |
getY()
Returns the pixel's y-coordinate within the image.
|
void |
setAlpha(int a)
Resets the value of the pixel's alpha (or transparency) component to the value passed as a parameter.
|
void |
setBlue(int b)
Resets the value of the pixel's blue component to the value passed as a parameter.
|
void |
setGreen(int g)
Resets the value of the pixel's green component to the value passed as a parameter.
|
void |
setRed(int r)
Resets the value of the pixel's red component to the value passed as a parameter.
|
java.lang.String |
toString()
Returns the string representation of the of the pixel.
|
public Pixel(Pixel other)
other
- another pixelpublic int getX()
public int getY()
public int getRed()
public int getGreen()
public int getBlue()
public int getAlpha()
public void setRed(int r)
r
- the red valuepublic void setGreen(int g)
g
- the green valuepublic void setBlue(int b)
b
- the blue valuepublic void setAlpha(int a)
a
- the alpha valuepublic java.lang.String toString()
toString
in class java.lang.Object