Convert Inno Setup Pascal Script TColor to HTML he

2019-06-12 17:42发布

问题:

Inno Setup Pascal Script has colour variables like clBtnFace, clYellow in Delphi.

I like to know how can I convert any of those TColor to HTML hex colour.

For example, if I convert clBtnFace to a HTML hex colour, the result should be #497AC2. And if I convert clYellow to a HTML hex colour, the result should be #FFFF00.

I found many examples for above, but they're for RGB colours. I want to convert TColor to HTML hex colour to use as hex colour in the command line parameters for ImageMagick in my Pascal Script like ...xc:#497AC2....

Thanks in advance.

回答1:

function ColorToWebColorStr(Color: TColor): string;
var
  RGB: Integer;
begin
  RGB := ColorToRGB(Color);
  Result :=
    UpperCase(Format('#%.2x%.2x%.2x', [Byte(RGB), Byte(RGB shr 8), Byte(RGB shr 16)]));
end;

For the ColorToRGB, see Converting Inno Setup WizardForm.Color to RGB.