Colors/es
From Lazarus wiki
Revision as of 15:00, 17 September 2015 by Jma sp (talk | contribs) (→Convert TColor to/from string)
Overview
In the LCL TColor is the standard color type. It is compatible with Delphi's TColor. TColor can represent either an RGB (3x8bit) value, or a system color like clDefault. The LCL can also work with the fpImage system which uses the TFPColor type (which is RGBA (4x16bit), not RGB (3x8bit) like TColor).
Conversions between TColor and RGB values
The Graphics unit provides the following functions:
function Blue(rgb: TColor): BYTE; // does not work on system color
function Green(rgb: TColor): BYTE; // does not work on system color
function Red(rgb: TColor): BYTE; // does not work on system color
function RGBToColor(R, G, B: Byte): TColor;
procedure RedGreenBlue(rgb: TColor; out Red, Green, Blue: Byte); // does not work on system color
function FPColorToTColor(const FPColor: TFPColor): TColor;
function TColorToFPColor(const c: TColor): TFPColor; // does not work on system color
function IsSysColor(AColor: TColorRef): Boolean;
Convert TColor to/from string
Functions to convert strings like "25500" or "$AA0088" or "clNavy" to TColor:
- StringToColor
- StringToColorDef
To convert TColor to a nice string:
- ColorToString
Table of standard colors
About 20 predefined color constants are provided, which are Delphi-compatible:
Colour constant | Meaning | Hexadecimal value for use with TColor | Example |
---|---|---|---|
clBlack | Black | TColor($000000); | |
clMaroon | Maroon | TColor($000080); | |
clGreen | Green | TColor($008000); | |
clOlive | Olive Green | TColor($008080); | |
clNavy | Navy Blue | TColor($800000); | |
clPurple | Purple | TColor($800080); | |
clTeal | Teal | TColor($808000); | |
clGray | Grey | TColor($808080); | |
clSilver | Silver | TColor($C0C0C0); | |
clRed | Red | TColor($0000FF); | |
clLime | Lime Green | TColor($00FF00); | |
clYellow | Yellow | TColor($00FFFF); | |
clBlue | Blue | TColor($FF0000); | |
clFuchsia | Fuchsia | TColor($FF00FF); | |
clAqua | Aqua | TColor($FFFF00); | |
clLtGray | Light Grey | TColor($C0C0C0); | clSilver alias |
clDkGray | Dark Grey | TColor($808080); | clGray alias |
clWhite | White | TColor($FFFFFF); | |
clCream | Cream | TColor($F0FBFF); | Lazarus 1.2 and newer |
clMedGray | Medium Grey | TColor($A4A0A0); | Lazarus 1.2 and newer |
clMoneyGreen | Mint Green | TColor($C0DCC0); | Lazarus 1.2 and newer |
clSkyBlue | Sky Blue | TColor($F0CAA6); | Lazarus 1.2 and newer |