Estoy intentando obtener los códigos RGB de una imagen pixel por pixel. Para esto, creé una matriz con las mismas dimensiones de la imagen:
cargaImagen ImagenCargada = new cargaImagen("SpriteSheet.png");
imagen = ImagenCargada.img;
alto=imagen.getHeight();
ancho=imagen.getWidth();
pixeles = new int[alto][ancho];
Luego, para obtener el RGB de cada pixel y guardarlo en mi matriz, uso el siguiente ciclo con la función getRGB:
for(int x=0; x<alto;x++){
for(int y=0; y<ancho; y++){
pixeles[x][y]=imagen.getRGB(x,y);
//System.out.println(imagen.getHeight()+" ancho:"+imagen.getWidth());
}
}
Pero al compilar me da este 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:917)
at animacion2.pkg0.HojaSprites.<init>(HojaSprites.java:31)
at animacion2.pkg0.Animacion20.main(Animacion20.java:27)