Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm exam 1 review Fall2005: Posterize

Back to Midterm Exam 1 Review Fall2005

Questions? Answers? Comments?



  public void posterize2()
  {
    Pixel pixel = null;
    int redValue = 0;
    int greenValue = 0;
    int blueValue = 0;
    
    // loop through the pixels
    for (int x = 0; x < this.getWidth(); x++) {
      for (int y = 0; y < this.getHeight(); y++) {
        
        // get the current pixel and colors
        pixel = this.getPixel(x,y);
        redValue = pixel.getRed();
        greenValue = pixel.getGreen();
        blueValue = pixel.getBlue();
        
        // check for red range and change color
        if (redValue < 128)
          redValue = 255;
        else if (redValue >= 128)
          redValue = 5;
        // check for green range
        if (greenValue > 10)
          greenValue = 200;
        else if (greenValue < 200)
          greenValue = 10;

        
        // check for blue range
        if (blueValue >= 250)
          blueValue = 200;
        else if (blueValue < 250)
          blueValue = 201;
        
        // set the colors
        pixel.setRed(redValue);
        pixel.setGreen(greenValue);
        pixel.setBlue(blueValue);
      }
    }
  }

Student159

that is what i was goign to put, high five betsy
Removed at KS request


Right back at you!
Student159



Link to this Page