I have a 2D array of size 320x240 which contains values ranging from 0 to 255. I want to store this data as a grayscale image.
This is the code I have written so far:
int val[320][240];
FILE *image = fopen("depth.png","wb");
for (i=0; i < 320; i++)
{
for (j=0; j<240; j++)
{
printf("\nWriting to pixel %d %d in image",i,j);
fwrite(&val[i][j], sizeof(int), sizeof(int),image);
}
}
fclose(image);
However this code does not produce a proper image. Please provide suggestions for correcting the code.