To analyze the brightness of red, green and blue from the TColor object

Source: Internet
Author: User

Use API functions Getrvalue,getbvalue and Getgvalue. Here is an example of changing the background color of a window by analyzing the red, green and blue. (Note: Before using the following example code, set the color of the window to clblue,clnavy or any other non-system color, such as Clbtnface)

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  BYTE nRed  = GetRValue(Color);
  BYTE nBlue = GetBValue(Color);
  BYTE nGreen = GetGValue(Color);
  nRed +=10;
  nBlue -=10;
  nGreen *= 1.05;
  Color =(TColor) RGB(nRed, nGreen, nBlue);
}

Note: The Get Series function returns a 0~255 brightness value. The return type is byte because a single brightness value is one byte. When you set the brightness value to less than 0 or greater than 255, the RGB macro truncates the extra bytes (it takes only a low 8 bits).

Note: Technically, these three get functions are not actually functions, they are C-style macros. You can see their implementation in the include\win32\wingdi.h. One result of using macros is that the function is not type-safe. You can pass char * to a macro without any warning.

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.