title: Change color of non-transparent parts of png in Java
body: <p>I am trying to automatically change the color for a set of icons. 
  Every icon has a white filled layer and the other part is transparent.
  Here is an example: (in this case it's green, just to make it visible)</p>
  
  <p><img src="https://i.stack.imgur.com/NWvnS.png" alt="icon search"></p>
  
  <p>I tried to do the following:</p>
  
  <pre><code>private static BufferedImage colorImage(BufferedImage image) {
          int width = image.getWidth();
          int height = image.getHeight();
  
          for (int xx = 0; xx &lt; width; xx++) {
              for (int yy = 0; yy &lt; height; yy++) {
                  Color originalColor = new Color(image.getRGB(xx, yy));
                  System.out.println(xx + "|" + yy + " color: " + originalColor.toString() + "alpha: "
                          + originalColor.getAlpha());
                  if (originalColor.equals(Color.WHITE) &amp;&amp; originalColor.getAlpha() == 255) {
                      image.setRGB(xx, yy, Color.BLUE.getRGB());
                  }
              }
          }
          return image;
      }
  </code></pre>
  
  <p>The problem I have is that every pixel I get has the same value:</p>
  
  <pre><code>32|18 color: java.awt.Color[r=255,g=255,b=255]alpha: 255
  </code></pre>
  
  <p>So my result is just a colored square.
  How can I achieve to change the color of the non-transparent parts only? And why is it, that all pixels have even the same alpha value? I guess that's my main problem: That the alpha value isn't read correctly.</p>