Re: Trouble with GetDIBits()
What does the GetDIBits return? And did you red the GetDIBits documentation?
Re: Trouble with GetDIBits()
Well, in my case the return value is 1, so I guess the pixel is successfully scanned. But whether or not I call GetDIBits(), the same characters are stored in the array. I did read the documentation of the function but I didn't find anything that could cause the error. What do you expect me to know from the documentation?
Re: Trouble with GetDIBits()
BYTE is a char.
cout << (BYTE)32;
outputs a character space (ascii value 32), not the value 32.
to display char's (BYTE's) as numeric values, typecast to int.
Re: Trouble with GetDIBits()
First, in your other thread COLORREF is 4-bytes, as it stores 32-bit values RGBA (RGB and Alpha for transparency). Both your examples declare 24-bit colour values, so you would need only 3-bytes per pixel. It's ok to use 4-bytes like COLORREF, but you would ignore the 4th byte each time as it would be 0. Though, that is a waste of memory.
In this example you are loading an image the size 1366x768. So you would need (1366 * 768 * 3) bytes to store it 3147264. Fortunately the width (768) is a multiple of 4, otherwise you would need to add some padding.
Should be more like
Code:
BYTE p[1366 * 768 * 3] // Can't actually be done
This would need to be done with new in the heap otherwise it will crash.
Code:
bmi.bmiHeader.biSizeImage=0;
This also needs to be the value of 1366 * 768 * 3.
Re: Trouble with GetDIBits()
Also, the fourth variable needs to be the image height (scanlines). So instead of:
Code:
GetDIBits(MemDC,hBit,0,0,p,&bmi,DIB_RGB_COLORS); // Incorrect
It should be more like:
Code:
GetDIBits(MemDC,hBit,0,768,p,&bmi,DIB_RGB_COLORS);