I have this kind of method:
public void SaveImageOntoObject(String filepath) throws IOException {
BufferedImage image = ImageIO.read(getClass().getResourceAsStream(filepath));
this.width = image.getWidth();
this.height = image.getHeight();
this.ResetPointInformation();
for (int row = 0; row < width; row++) {
for (int col = 0; col < height; col++) {
this.PointInformation[row][col] = new Color(image.getRGB(col, row));
}
}
}
It takes the filepath of an image as input, converts the RPG Value of each pixel into a Color Object and then stores it into the two-dimensional Array PointInformation of the Object the Method was called onto.
Now to my problem:
While some pictures like this one:

Work like a charm, others like this:

Let me end up with the error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:318)
at java.awt.image.BufferedImage.getRGB(BufferedImage.java:888)
at Drawing.Object2D.SaveImageOntoObject(Object2D.java:75)** (that's the class whose object's my method works on)
Why is that like that? It seems like Java is not able to convert certain RGB values into Colors?
Could you tell me how I can make it work?
The error message actually says it: “index out of bounds”. It seems, that you confused your coordinates and their bounds.
getRGBtakes the parametersx(range 0 ..width) as first, andy(range 0 ..height) as second.Your first example has width = height, so that the problem doesn’t show.