I need to print the a ppm picture but the output isn't organized as it should be, my code:
public static int[][][] read(String filename) {
StdIn.setInput(filename);
StdIn.readLine();
int imgW = StdIn.readInt ();
int imgH = StdIn.readInt ();
int[][][] data = new int[imgH][imgW][3];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
for (int k = 0; k < data[i][j].length; k++) {
data[i][j][k] = StdIn.readInt();
}
}
}
return data;
}
my output:
255 0 0 0 100 0 0 0 0 0 255 0
the correct output: (basically same like a matrix)
255 0 0 0 0 255 175 0 0 0 0 0
0 0 0 0 0 0 0 0 15 175 0 0
0 255 0 255 0 0 0 0 0 0 255 255
0 0 0 100 0 0 0 0 0 255 0 255
0 0 0 0 255 175 0 0 0 0 0 0
0 0 0 0 0 0 0 15 175 0 0 0
255 0 255 0 0 0 0 0 0 255 255 255
Ppm files also lists the maximum value appearing in the file, which is the 255 in the beginning of your output.
You should add an extra StdIn.readInt(); before your loop.