Pixel
Method Details
getX
public int getX()
Gets the x coordinate of this Pixel
in the image.
Examples
Pixel currentPixel = imagePixels[10][20];
int xLocation = currentPixel.getX();
System.out.println("This pixel is located at x position " + xLocation);
Output:
This pixel is located at x position 20
getY
public int getY()
Gets the y coordinate of this Pixel
in the image.
Examples
Pixel currentPixel = imagePixels[10][20];
int yLocation = currentPixel.getY();
System.out.println("This pixel is located at y position " + yLocation);
Output:
This pixel is located at y position 10
getSourceImage
public Image getSourceImage()
Gets the image that this Pixel
is part of.
Examples
Pixel currentPixel = imagePixels[10][20];
Image sourceImage = currentPixel.getSourceImage();
getColor
public Color getColor()
Gets the color of the Pixel
in the image.
Examples
Pixel currentPixel = imagePixels[10][20];
Color pixelColor = currentPixel.getColor();
setColor
public void setColor(Color color)
Sets the color of this Pixel
in the image to the specified Color
.
Parameters
Name | Type | Description |
---|---|---|
color | Color | the color to set this |
Examples
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];
Color testColor = new Color(249, 181, 172);
currentPixel.setColor(testColor);
}
}
getRed
public int getRed()
Returns the amount of red (ranging from 0 to 255) in the color of this Pixel
.
Examples
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];
int currentRed = currentPixel.getRed();
}
}
getGreen
public int getGreen()
Returns the amount of green (ranging from 0 to 255) in the color of this Pixel
.
Examples
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];
int currentGreen = currentPixel.getGreen();
}
}
getBlue
public int getBlue()
Returns the amount of blue (ranging from 0 to 255) in the color of this Pixel
.
Examples
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];
int currentBlue = currentPixel.getBlue();
}
}
setRed
public void setRed(int value)
Sets the amount of red (ranging from 0
to 255
) in the color of this Pixel
. Values below 0
will be ignored and set to 0
, and values above 255
with be ignored and set to 255
.
Parameters
Name | Type | Description |
---|---|---|
value | int | the amount of red (ranging from |
Examples
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];
currentPixel.setRed(100);
currentPixel.setGreen(0);
currentPixel.setBlue(0);
}
}
setGreen
public void setGreen(int value)
Sets the amount of green (ranging from 0
to 255
) in the color of this Pixel
. Values below 0
will be ignored and set to 0
, and values above 255
with be ignored and set to 255
.
Parameters
Name | Type | Description |
---|---|---|
value | int | the amount of green (ranging from |
Examples
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];
currentPixel.setRed(0);
currentPixel.setGreen(100);
currentPixel.setBlue(0);
}
}
setBlue
public void setBlue(int value)
Sets the amount of blue (ranging from 0
to 255
) in the color of this Pixel
. Values below 0
will be ignored and set to 0
, and values above 255
with be ignored and set to 255
.
Parameters
Name | Type | Description |
---|---|---|
value | int | the amount of blue (ranging from |
Examples
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];
currentPixel.setRed(0);
currentPixel.setGreen(0);
currentPixel.setBlue(100);
}
}