I've no idea what the issue is. I'm trying to load the pixel data of a bitmap into an array. I'm using std::istream::read to read in the pixel data. Maybe that doesn't do what I thought it did? I don't know because all that's in my array is the null termination character after reading in the data. All the other info in the bmp is read fine. Image size, width, height, bits per pixel, offset to raster data all fine. Just when I actually attempt to read the raster data do I encounter difficulties.
Well this is unrelated to your problem, but you have a huge memory leak because you never delete[] your array. Consider using a smart pointer or a vector.
That said....
I don't know because all that's in my array is the null termination character after reading in the data.
null termination character... as in 0?
does your bitmap have black pixels? Because that would have 0s in it.
I don't see anything that would cause the kind of failure you're describing. How are you examining the pixel data?
Yes, I'm aware of the leak. That was just some test code to see if I could get it loaded. And by null termination character I mean /0. I'm not currently doing anything with the pixel data yet other than try to load it into the array as raw unformatted data.
The existence of zeros doesn't make it wrong on its own -- it's very possible for valid pixel data to contain zeros.
And by null termination character I mean /0
'\0' is not a special character, it is just the literal value of 0 cast to a char.
The same way '\1' is a literal value of 1, and '\2' is a literal value of 2:
1 2 3 4
if('\0' == 0)
cout << "this will print";
if('\101' == 'A') // 101 in octal is 0x41 in hex. Which is the ASCII code for the letter 'A'
cout << "this will also print";
When I try to print out the array, it doesn't print anything. Also when I step through the program the ONLY thing I see in the array is 0'\0'. There should be as many elements as the size of m_imageSize, correct?
When I try to print out the array, it doesn't print anything.
Printing binary data doesn't work.
Also when I step through the program the ONLY thing I see in the array is 0'\0'.
Viewing binary data as a c string doesn't work for the same reason printing it doesn't work.
Unlike with strings, 0 does not mark the end of the data, here. It is just another value a byte can have. For example, a black pixel will have 0 four times in a row.
There should be as many elements as the size of m_imageSize, correct?
There are. The problem is you are viewing the data as a string, and therefore it stops showing you info once it reaches the first 0 byte.