How to get the red, green, and blue values of the colors on the screen

Source: Internet
Author: User

On the desktop to run a variety of programs, there are many colors are very beautiful, we sometimes want to use their colors, but suffer from no source code, so it is difficult to accurately know their R, G, B color values. So there are a lot of tools to pick up screen colors, do you want to know how they are implemented with the program? I'll take the example code of a screen color picker I made with VC6.0 to tell you that the interface of the instance program after running is as follows:

Basic composition thought:

The principle is simple, only a brief three-step. Both: Get the screen DC, get the current mouse pixel value, decomposition of the pixel value of red, green, blue Three colors can, very simple!

Key code implementations:

1. Get the screen DC

HDC hDC = ::GetDC(NULL); //获取屏幕DC

2, get the current mouse position pixel value

CPoint pt;
GetCursorPos(&pt);        //得到当前鼠标所在位置
COLORREF clr = ::GetPixel(hDC, pt.x, pt.y); //获取当前鼠标点像素值

3, the decomposition of the pixel point of red, green, blue color values

CString ClrText;
ClrText.Format("%d",GetRValue(clr));     //分解出红色值
ClrText.Format("%d",GetGValue(clr)); //分解出绿色值
ClrText.Format("%d",GetBValue(clr)); //分解出蓝色值
::ReleaseDC(NULL, hDC); //释放屏幕DC

The details of the implementation of the above part of the code, you can download the instance code, carefully check the source can be (with detailed comments).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.