Midterm Exam 1 Review-Fall 2007: Posterize
Back to Midterm Exam 1 Review-Fall 2007
Ask your questions here...
Question: Would I have to do anything besides change the conditions inside the if statements for the first question? On a test would we have to do a while loop since you gave a for loop? |
- For this question all you really have to do is to change the conditionals though you could change the for loops to while loops if you desired. If we want you to do anything as a requirement for the problem, it would be clearly stated in the problem itself. Dawn Finney.
public void newPosterize(){
Pixel pixel = null;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
for (int x = 0; x< this.getWidth(); x++){
for (int y=0 ; y< this.getHeight(); y++){
pixel = this.getPixel(x,y);
redValue = pixel.getRed();
greenValue=pixel.getGreen();
blueValue = pixel.getBlue();
if (redValue < 128 )
redValue = 255;
else if (redValue <= 128)
redValue = 5;
if (greenValue < 10)
greenValue = 200;
else if (greenValue >200)
greenValue = 10;
if (blueValue <= 250)
blueValue = 200;
else if (blueValue > 250)
blueValue = 201;
pixel.setRed(redValue);
pixel.setGreen(greenValue);
pixel.setBlue(blueValue);
}
}
}
Link to this Page