title: Java BufferedImage.getRGB () - Coordinate out of bounds
body: <p>So, I'm trying to the color of a specific pixel in an BufferedImage...</p>
  
  <pre><code>public void LoadImageLevel (BufferedImage image) {
  
      int w = image.getWidth ();
      int h = image.getHeight ();
  
      System.out.println (w + " " + h);
  
      for (int xx = 0; xx &lt; h; xx++) {
  
          for (int yy = 0; yy &lt; w; yy++) {
  
              int pixel = image.getRGB (xx, yy);
  
              int red = (pixel &gt;&gt; 16) &amp; 0xff;
              int green = (pixel &gt;&gt; 8) &amp; 0xff;
              int blue = (pixel) &amp; 0xff;
  
              if (red == 255 &amp;&amp; green == 255 &amp;&amp; blue == 255) {
  
                  handler.addObject (new Block (xx * 32, yy * 32, ObjectID.Block, 32, 32));
              }
          }
      }
  }
  </code></pre>
  
  <p>And it's called from the Main class constructor:</p>
  
  <pre><code>    ImageLoader imageLoader = new ImageLoader ();
  
      level = imageLoader.loadImage ("/levels/level_test.png");
  
      LoadImageLevel (level);
  </code></pre>
  
  <p>The BufferedImage is loaded from my BufferedImageLoader class:</p>
  
  <pre><code>import java.awt.image.BufferedImage;
  import java.io.IOException;
  
  import javax.imageio.ImageIO;
  
  public class ImageLoader {
  
      private BufferedImage image;
  
      public BufferedImage loadImage (String path) {
  
          try {
  
              image = ImageIO.read (getClass ().getResource (path));
  
          } catch (IOException e) {
  
              e.printStackTrace ();
          }
  
          return image;
      }
  }
  </code></pre>
  
  <p>When I run the project I get this error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:   Coordinate out of bounds!
      at sun.awt.image.ByteInterleavedRaster.getDataElements(Unknown Source)
      at java.awt.image.BufferedImage.getRGB(Unknown Source)
      at com.main.index.Game.LoadImageLevel(Game.java:190)
      at com.main.index.Game.&lt;init&gt;(Game.java:41)
      at com.main.index.Game.main(Game.java:206)
  </code></pre>
  
  <p>Line 190 is the "int pixel = image.getRGB (xx, yy);", line 41 is where it's called in the constructor, and line 206 is the main method.</p>
  
  <hr>
  
  <p>Thanks in advance! ^_^</p>