Mirror

Get a color string in HTML format (Views: 101)


Problem/Question/Abstract:

How can I receive the color string in HTML format

Answer:

If you want to create a HTML-file, you must define a tag for font color or backgroubd color. But you can't insert a Delphi's TColor value - you must convert the color into RGB-format.

function GetHTMLColor(cl: TColor; IsBackColor: Boolean): string;
var
  rgbColor: TColorRef;
begin
  if IsBackColor then
    Result := 'bg'
  else
    Result := '';
  rgbColor := ColorToRGB(cl);
  Result := Result + 'color="#' +
    Format('%.2x%.2x%.2x',
    [GetRValue(rgbColor),
    GetGValue(rgbColor),
      GetBValue(rgbColor)]) + '"';
end;

<< Back to main page