XBa*_*000 13 delphi image color-picker
如何根据背景自动获得正确的颜色?如果它的背景图像较暗,则会自动将字体颜色更改为更亮的颜色.有可能吗?任何的想法?
And*_*and 25
大卫的答案通常都很有效.但是有一些选择,我会提到其中的一些.首先,最天真的方法是做
function InvertColor(const Color: TColor): TColor;
begin
result := TColor(Windows.RGB(255 - GetRValue(Color),
255 - GetGValue(Color),
255 - GetBValue(Color)));
end;
Run Code Online (Sandbox Code Playgroud)
但这有#808080问题(为什么?).一个非常好的解决方案是大卫的,但它看起来非常糟糕的一些不幸的背景颜色.虽然文字肯定是可见的,但它看起来很糟糕.一种这样的"不幸"背景颜色是#008080.
通常,如果背景为"浅色",我希望文本为黑色;如果背景为"暗",则优选为白色.我这样做
function InvertColor(const Color: TColor): TColor;
begin
if (GetRValue(Color) + GetGValue(Color) + GetBValue(Color)) > 384 then
result := clBlack
else
result := clWhite;
end;
Run Code Online (Sandbox Code Playgroud)
此外,如果您使用的是Delphi 2009+并针对Windows Vista +,您可能会对该GlowSize参数感兴趣TLabel.
Dav*_*nan 13
我使用以下内容给我一种与指定颜色形成鲜明对比的颜色:
function xorColor(BackgroundColor: TColor): TColor;
begin
BackgroundColor := ColorToRGB(BackgroundColor);
Result := RGB(
IfThen(GetRValue(BackgroundColor)>$40, $00, $FF),
IfThen(GetGValue(BackgroundColor)>$40, $00, $FF),
IfThen(GetBValue(BackgroundColor)>$40, $00, $FF)
);
end;
Run Code Online (Sandbox Code Playgroud)