I am working on getting a real-time stream of the desktop to display in openFrameworks (for further work).
Using the Windows API, an image of the screen in HBITMAP (handler) is acquired, then a BITMAP byte array from the HBITMAP.
I am currently translating the BITMAP BYTE array to ofPixel array:
I tried saving the screen as a .bmp file and everything looks fine, but when trying to assign values to the ofPixels array (so that further image manipulation can be done in openFrameworks), the resulting image is as shown above.
So, I am trying to get around this by looking at the raw array values and figuring out how I could be assigning the values wrongly.
[Update 7 Feb 2017:]
After realising that bitmap colours are stored as Blue-Green-Red-Alpha in the byte array instead of the usual RGBA, I switched the values appropriately when creating ofColor to set the pixel colour in the ofPixel object.
Just in case there was something wrong with how I calculated the index of the pixel’s location in ofPixel, I tried using the same function with a different set of parameters:
ofPixels::setColor(int x, int y, ofColor newColor)
instead of calculating the index for this function to set the colours of the output image:
ofPixels::setColor(int index, ofColor newColor)
It worked perfectly
and I feel stupid now after spending so much time trying to figure out what was wrong. Yay.