title: IllegalArgumentException: Color parameter outside of expected range: Red Green Blue
body: <p>when I tested my code with JUnit, the following error occured:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue
  </code></pre>
  
  <p>Honestly, I don't know why. My code is not very long, so I would like to post it for better help.</p>
  
  <pre><code>BufferedImage img = ImageIO.read(f);
          for (int w = 0; w &lt; img.getWidth(); w++) {
              for (int h = 0; h &lt; img.getHeight(); h++) {
                  Color color = new Color(img.getRGB(w, h));
                  float greyscale = ((0.299f * color.getRed()) + (0.587f
                          * color.getGreen()) + (0.144f * color.getBlue()));
                  Color grey = new Color(greyscale, greyscale, greyscale);
                  img.setRGB(w, h, grey.getRGB());
  </code></pre>
  
  <p>When I run the JUnit test, eclipse marks up the line with</p>
  
  <pre><code>Color grey = new Color(greyscale, greyscale, greyscale);
  </code></pre>
  
  <p>So, I suppose the problem might be, that I work with floating numbers and as you can see I recalculate the red, green and blue content of the image.</p>
  
  <p>Could anyone help me to solve that problem?</p>