Tuesday 11 December 2012

Determine if a colour light

Below is a Delphi function to determine whether a colour is light, this is useful if a user can for example change the background colour of a control, you will need then to set the font colour correctly.


function ColourIsLight(Colour: TColor): boolean;
begin
    Colour := ColorToRGB(Colour);
    Result := ((Colour and $FF) + (Colour shr 8 and $FF) + (Colour shr 16 and    $FF)) >= $180;
end;

No comments:

Post a Comment