 |  |

 |
 |  |  |
 | Free Iran!
THE CAKE IS A LIE
THE CAKE IS A LIE
THE CAKE IS A LIE
|  |
 |  |  |
|
|
|
        |
FinalExam Review Fall2005: From Decrease to Gray
Questions? Comments? Answers?
(Back to Final Exam Review Fall2005)
/**
*Method to Grayscale*/
public void decreaseGray()
{
Pixel pixel = null; // the current pixel
int redValue; // the amount of red
int greenValue; // the amount of green
int blueValue; // the amount of blue
int grayValue; //gray value
// get the array of pixels for this picture object
Pixel[] pixels = this.getPixels();
// start the index at 0
int index = 0;
// loop while the index is less than the length of the pixels array
while (index < pixels.length)
{
// get the current pixel at this index
pixel = pixels[index];
// get the red value at the pixel
redValue = pixel.getRed();
greenValue = pixel.getGreen();
blueValue = pixel.getBlue();
grayValue = (redValue+greenValue+blueValue)/3
// set the red for this pixel to the new value
pixel.setRed(grayValue);
pixel.setGreen(grayValue);
pixel.setBlue(grayValue);
// increment the index
index++;
}
}
Kyle DuPont
Link to this Page