delphi TColor format Negative

依然范特西╮ 提交于 2020-11-29 09:14:12

问题


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


回答1:


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).




回答2:


Delphi defines the Windows system colors like

SysGradientInactiveCaption = TColor(SystemColor or cGRADIENTINACTIVECAPTION);

With

SystemColor = $FF000000;

and

cGRADIENTINACTIVECAPTION = 28;

this ends up as -16777188.

These constants can be found in System.UITypes.pas under TColorRec.



来源:https://stackoverflow.com/questions/62263083/delphi-tcolor-format-negative

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!