Accessing a file, assigning it to an array
Okay, I think my major problem here is that the professor provided a method that he explicitly told us we would not understand... so I'm unable to see what I'm even doing wrong here. This is my code (the main method I wrote, and the readImageintoArray is the method he wrote).
Essentially, I need this GrayScaleData array to be used in other methods of the program, which would be ComputeImageStatistics and displayGrayscaleImage (as you can see in the main method). This GrayScaleData is being created by a color image that is being converted into a black, white, and gray image. What am I doing wrong here?
public static void main (String  args)
public static int readImageintoArray(String filename)
File f = new File(filename);
BufferedImage readimage = null;
readimage = ImageIO.read(f);
catch (IOException e)
int imageWidth = readimage.getWidth();
int imageHeight = readimage.getHeight();
int GrayScaleData = new int[imageWidth][imageHeight];
for (int i = 0; i < imageHeight; i++)
for (int j = 0; j < imageWidth; j++)
int pixel = readimage.getRGB(j, i);
GrayScaleData[j][i] = (((pixel >> 16) & 0xff) + ((pixel >> 8) & 0xff) + ((pixel) & 0xff)) / 3;