Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

delphi TColor format Negative

hopefully an easy question, but I could not find an answer. I am using Delphi TColor and some color values are negative. Is this documented? I need to do some color conversions, for example, to RGB.

for example: Label.Color=-16777188; //light bluish

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The negative values are not actual RGB colours, but Windows system colours, which are variable.

For instance, the following are actual RGB colours:

clRed   = $000000FF; {00BBGGRR}
clBlue  = $00FF0000;
clWhite = $00FFFFFF;
clBlack = $00000000;

Here are some system colours:

clWindow        = $FF000005;
clWindowText    = $FF000008;
clHighlight     = $FF00000D;
clActiveCaption = $FF000002;

These are not actual RGB values, but represent your system colours. Often, clWindow is white, clWindowText is black, clHighlight is some kind of blue etc., but -- again -- these settings can be changed in Windows.

When these 32-bit integers are interpreted as signed 32-bit integers, they become negative. That's what you are seeing:

clWindow        = -16777211;
clWindowText    = -16777208;
clHighlight     = -16777203;
clActiveCaption = -16777214;

So in your case, -16777188 is not guaranteed to be "light bluish". In hex, this value is $FF00001C and I recognize this as clGradientInactiveCaption, that is, the second gradient colour of an inactive unthemed (Windows 9x-styled) window titlebar.

As you know, in the VCL you can use these system colours as if they were actual colours. But -- of course -- the actual colours you get might vary from user to user.

You can obtain an actual RGB colour from such a system colour by using the ColorToRGB function. On my system, ColorToRGB(clGradientInactiveCaption) yields $00F2E4D7 (indeed light bluish).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...