Ok, im trying with GetDIBits but i cant make it work.
It always returns senseless values.
I think im missing the purpose of HDC here. Can someone explain this please? I mean, what's it for???
Note:
1) The image is a screenshot which i take just before running the code by pressing 'PrtScreen' button on the keyboard.
2) GetDIBits scans line 500 which, since im on a resolution of 1280x1024, is approximately in the middle of the screen.
3) Color depth is 32bits.
Instead, you could also request a CF_BITMAP - but that would require you to keep guessing the bitmap format and dimensions (or call GetObject to get them), so CF_DIB is the more convenient approach here.
Thanks a lot for that Athar, now im able to save the .bmp file.
But i still have problems with the rgb values. First, im trying to retrieve rgb values of single pixels, so filling the bitmapBits with the values of all is too much. Even scanning a single line as i was trying to do with GetDIBits is too much actually. For example, i would need only the rgb values of the 400th pixel on line 500. Only that. How to accomplish this without external libraries and through the clipboard?
Secondly, the following code im using now, still returns senseless rgb values.
What am i missing?
This is fairly easy, although there are a few things to keep in mind:
1. Bitmaps are saved row-based.
2. When the height is positive, it is a bottom-up bitmap, that is, the last line comes first in memory.
3. A row must be aligned on a 4-byte boundary.
4. Color channel order is BGR (unless specified otherwise by BI_BITFIELDS masks).
To extract a single pixel, you can use this. If you want to extract several, you should move this code into a helper class and provide a member function getPixel.