can someone help to write a method that converts a byte array to a 2-dimensional int array?!
I have written that:
internal int[][] byteToInt(byte[] byteArray)
{
int width = (int)Math.Sqrt(byteArray.Length);
int[][] tmp = new int[width][];
for (int i = 0; i < width; i++)
{
tmp[i] = new int[width];
}
for (int i = 0; i < width; i++)
{
for (int j = 0; j < width; j++)
{
tmp[i][j]=(int)byteArray[(i*width+j)];
}
}
return tmp;
}
but that is not working properly….
OK I think this will do what you want.
If I understand correctly you want to take an image and convert it into a 2-dimensional array of int RGB values.
Although it doesn’t answer the main question it does solve the problem and the solution to the question would not have.
In answer to the main question there is no way to arbitrarily take a byte array and make it into a 2-dimensional int array as you have no idea what the dimensions of the 2-dimensional array will be.
The code you are using to get the image from the file is the correct way to get the raw binary of a jpg file but it doesn’t get the image it self. (see wikipedia for how jpeg files are formated)