I am trying to convert this PNG image by this method from an BufferedImage to an double array.
public double[][] bufferedToArray(File pngImage)
{
double[][] imageMatrix= null;
try {
final BufferedImage image = ImageIO.read(pngImage);
int height= image.getHeight();
int width= image.getWidth();
imageMatrix= new double[height][width];
System.out.println("Matriz Máximo i: " + imageMatrix.length +
"Matriz Máximo j: " + imageMatrix[0].length );
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
//System.out.println("i atual: "+i+" j atual: "+j);
imageMatrix[i][j] = image.getRGB(i, j); //The error is in this line.
//System.out.println("matrizImagem["+i+"]["+j+"] Inserido");
}
}
} catch (IOException e) {
e.printStackTrace();
}
return imageMatrix;
}
Even I define array to exactly size of the image height and width I am getting the error of the bounds, when it's almost completing the looping. I don't know why.
"Coordinate out of bounds! at sun.awt.image.ByteInterleavedRaster.getDataElements(Unknown Source) at java.awt.image.BufferedImage.getRGB(Unknown Source)"