how to get the right color automatically that is depending on the background? if its darker background image, that will automatically change the font color into brighter colors. was it possible? any idea?
The opposite of the color red is green.
CSS allows you to invert the color of an HTML element by using the invert() CSS function that you can pass to the filter property. Because the default color of the text is black, the color is inverted into white with filter: invert(100%) syntax.
David's answer is generally working very well. But there are a few options, and I will mention some of them. First, the very most naïve approach, is to do
function InvertColor(const Color: TColor): TColor;
begin
result := TColor(Windows.RGB(255 - GetRValue(Color),
255 - GetGValue(Color),
255 - GetBValue(Color)));
end;
but this suffers from the #808080 problem (why?). A very nice solution is David's, but it looks very bad for some unfortunate background colours. Although the text is certainly visible, it looks horrible. One such "unfortunate" background colour is #008080.
Usually I prefer the text to be black if the background is "light", and white if the background is "dark". I thus do
function InvertColor(const Color: TColor): TColor;
begin
if (GetRValue(Color) + GetGValue(Color) + GetBValue(Color)) > 384 then
result := clBlack
else
result := clWhite;
end;
Also, if you are using Delphi 2009+ and targeting Windows Vista+, you might be interested in the GlowSize
parameter of the TLabel
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With