title: How to change the brightness of an Image
body: <p><strong>My Question:</strong> I want to be able to change the brightness of a resource image and have three instances of it as ImageIcons. One at 50% brightness (so darker), another at 75% brightness (a little brighter), and finally another at 100% brightness (the same as the original image). I also want to preserve transparency.</p>
  
  <p><strong>What I've tried:</strong> I've searched around and it looks like the best solution is using <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/image/RescaleOp.html" rel="noreferrer"><code>RescaleOp</code></a>, but I just can't figure it out. I don't know what the scaleFactor and the offset is all about. Here's my code for what I've tried.</p>
  
  <pre><code>public void initialize(String imageLocation, float regularBrightness, float focusedBrightness, float pressedBrightness, String borderTitle) throws IOException {
    BufferedImage bufferedImage = ImageIO.read(ButtonIcon.class.getResource(imageLocation));
    setRegularIcon(getAlteredImageIcon(bufferedImage, regularBrightness));
    setFocusedIcon(getAlteredImageIcon(bufferedImage, focusedBrightness));
    setPressedIcon(getAlteredImageIcon(bufferedImage, pressedBrightness));
    setTitle(borderTitle);
    init();
  }
  
  private ImageIcon getAlteredImageIcon(BufferedImage bufferedImage, float brightness) {
    RescaleOp rescaleOp = new RescaleOp(brightness, 0, null);
    return new ImageIcon(rescaleOp.filter(bufferedImage, null));
  }
  </code></pre>
  
  <p>The call would be something like this:</p>
  
  <pre><code>seeATemplateButton.initialize("/resources/templateIcon-regular.png", 100f, 75f, 50f, "See A Template");
  //I think my 100f, 75f, 50f variables need to change, but whenever I change them it behaves unexpectedly (changes colors and stuff).
  </code></pre>
  
  <p><strong>What happens with that code:</strong> The image appears "invisible" I know it's there because it's on a JLabel with a mouse clicked event on it and that works just fine. If I just skip the brightness changing part and say <code>setRegularIcon(new ImageIcon(Button.class.getResource(imageLocation));</code> it works just fine, but obviously it's not any darker.</p>
  
  <p><strong>What I think I need:</strong> Some help understanding what <code>offset</code>, <code>scaleFactor</code>, and the <code>filter</code> method mean/do, and consequently what numbers to give for the brightness variable.</p>
  
  <p>Any help would be greatly appreciated! Thanks!</p>