I am reading a file and trying to get image width and height. However, I am getting an exception whenever I am calling this line
inImg.getRaster().getPixels(0,0,width,height,pixels);
The exception I am getting is
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 307200
at sun.awt.image.ByteInterleavedRaster.getPixels(ByteInterleavedRaster.java:1014)
at sobel_java.main(sobel_java.java:22)
My code is
public class Sobel {
public static void main(String[] args) throws IOException{
int i, j;
double Gx[][], Gy[][], G[][];
FileInputStream inFile = new FileInputStream("lena.bmp");
BufferedImage inImg = ImageIO.read(inFile);
int width = inImg.getWidth();
int height = inImg.getHeight();
int[] pixels = new int[width * height];
int[][] output = new int[width][height];
inImg.getRaster().getPixels(0,0,width,height,pixels);
}}
Thanks for your help.