How to get the red, green, blue value of each color on the screen

zhaozj2021-02-08  234

How to get the red, green, blue value of each color on the screen

Author: Xu Jing Zhou

Download sample source code (http://www.vckbase.com/code/viewcode.asp?id=1602)

In the desktop, there are many colors very beautiful. We sometimes want to use their color, but it is hard to accurately know the R, G, B color value. So I produce a lot of tools that pick the screen color. Do you want to know how they use the program? Below I will take me with the instance code of a screen color pickup made by VC6.0, telling you that the interface after the instance program is running as follows:

Basic composition of ideas:

The principle is simple, only three steps need to be briefly. None: Get screen DC, get the pixel value of the current mouse, decompose red, green, blue three colors in the pixel value, very simple!

Key code implementation:

1, get the screen DC

HDC HDC = :: getdc (null); // Get screen DC

2, get the current mouse position pixel value

Cpoint pt;

GetCursorpos (& PT); // Get the current mouse location

ColorRef CLR = :: getpixel (hdc, pt.x, pt.y); // Get the current mouse point pixel value

3, decompose red, green, blue color value in the pixel point

CString Clrtext;

CLRText.format ("% D", GtrValue (CLR)); // Decompose red value

CLRText.format ("% D", getgvalue (clr)); // Decompose green value

CLRText.format ("% D", getBvalue (CLR)); // Decompose blue value

:: ReleaseDC (NULL, HDC); // Release Screen DC

The details of the specific implementation of the above part of the code can be downloaded after downloading the instance code, and the source code can be carefully viewed (in detail).

Contact information:

Author email: jingzhou_xu@163.com

Future Studio (Future Studio)

转载请注明原文地址:https://www.9cbs.com/read-2108.html

New Post(0)