I've always used GetRValue
, GetGValue
and GetBValue
functions (From Winapi.Windows
unit) for extracting the RGB values for a TColor
.
Unfortunately, the same approach does not seem to be good for system colors like clWindow
, clBtnFace
and so on.
For example:
var
MyColor : TColor;
begin
MyColor := clBtnFace;
ShowMessage(
'R = ' + IntToStr(GetRValue(MyColor)) + sLineBreak +
'G = ' + IntToStr(GetGValue(MyColor)) + sLineBreak +
'B = ' + IntToStr(GetBValue(MyColor))
);
end;
It produces the following output:
R = 15
G = 0
B = 0
Which should looks like this:
On my system, I see the following color instead:
Using Get(R|G|B)Value()
will work just fine with system colors, you just need to convert them to RGB first. Use the ColorToRGB()
function for that:
Converts a TColor value into an RGB representation of the color.
For example:
var
MyColor: TColor;
RGB: Longint;
begin
MyColor := ...; // any valid TColor value, whether RGB or system constant...
RGB := ColorToRGB(MyColor);
ShowMessage(
'R = ' + IntToStr(GetRValue(RGB)) + sLineBreak +
'G = ' + IntToStr(GetGValue(RGB)) + sLineBreak +
'B = ' + IntToStr(GetBValue(RGB))
);
end;