Goal:
The aim of this code is to read in a .BMP, check each pixel, if black record 0, if not record 1 into a 2D Array.
Problem:
After assigning values into the Array (Arr), future output of Arr shows all rows as the same values, which happen to match the final values read from .BMP
However, if I output values to screen (cout) or a .TXT file as I read them from the .BMP, I get what I expect. I have tried assigning values to Arr as I read values from .BMP or from the .TXT file and get same undesired results.
Question:
What am I doing wrong when assigning values to the Array? Or am I reading from the Array incorrectly?
System and disclaimers:
I am using Dev-C++ on a Windows 7 machine. I have limited experience with C++ but am trying to learn. I've worked through several tutorials on C++ and tried reading about .bmp's to get this code. I've tried several versions of reading .bmp's into arrays and this version is working best so I'd prefer recommendations to fix this instead of complete rewrites.
VLA's are not legal in standard C++, although gcc provides an extension (enabled by default) that allows them. Know that this code is not going to work with another compiler, or with your current one if you change some settings.
Perhaps you could show up us the code that isn't working. It's hard to say what's being done wrong when one can't see what's being done.
An example of how the code wasn't working as I was expecting:
Direct output to screen, or to .TXT file, showed:
000111000
011001011
001101100
000111000
001110000
Whereas assigning values to the array and then outputting the array provided:
001110000
001110000
001110000
001110000
001110000
Now that I know I can't use VLA's, I have a work around for this project. I know that all of my .BMP's will be no more than a certain size, say 100x100. Not very large images. As such, I can define my array as Arr[100][100], set all values to 0, and then read the image into that array. (Making this change into the above code gets me the results I expected).
For future projects, or if I start working with larger images, then I'll find a better way to handle this.