I would like to get the RGB values of a pixel at different x, y coordinates on the screen. How would I go about this in C++?
I'm trying to create my own gaussian blur effect.
This would be in Windows 7.
Edit
What libraries need to be included for this to run?
What I have going:
#include <iostream>
using namespace std ;
int main(){
HDC dc = GetDC(NULL);
COLORREF color = GetPixel(dc, 0, 0);
ReleaseDC(NULL, dc);
cout << color;
}
Use the ColorSync Utility calculator to get the color values of a pixel on your screen. In the ColorSync Utility app on your Mac, click Calculator in the toolbar of the ColorSync Utility window. Click the magnifying glass , then move your pointer over an area on the screen that you want to examine.
The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
Each pixel on a computer screen is composed of three small dots of compounds called phosphors surrounded by a black mask. The phosphors emit light when struck by the electron beams produced by the electron guns at the rear of the tube. The three separate phosphors produce red, green, and blue light, respectively.
You can use GetDC
on the NULL
window to get a device context for the whole screen, and can follow that up with a call to GetPixel
:
HDC dc = GetDC(NULL);
COLORREF color = GetPixel(dc, x, y);
ReleaseDC(NULL, dc);
Of course, you'd want to only acquire and release the device context once while doing all the pixel-reading for efficiency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With