在 Inno Setup Pascal 脚本中将 HTML 十六进制颜色转换为 TColor
Convert HTML hex colour to TColor in Inno Setup Pascal Script
我想在 Inno Setup Pascal 脚本中将 HTML 十六进制颜色转换为 TColor
。
我尝试从 反转函数 ColorToWebColorStr
,但我可能需要像 RGBToColor
这样的函数才能得到 TColor
.
的结果
示例:#497AC2
HTML 十六进制颜色的转换应返回为 TColor
$C27A49
.
输入应为 HTML 颜色字符串表示,输出应为 TColor
.
当我在 Inno Setup 中使用 VCL Windows
单元的以下功能时,TForm.Color
显示为红色。
const
COLORREF: TColor;
function RGB( R, G, B: Byte): COLORREF;
begin
Result := (R or (G shl 8) or (B shl 16));
end;
DataChecker.Color := RGB( 73, 122, 194);
我在TForm.Color
中期望的颜色是:
<html>
<body bgcolor="#497AC2">
<h2>This Background Colour is the Colour I expected instead of Red.</h2>
</body>
</html>
另外,我也想知道为什么这里返回的是红色(显示红色的表格)而不是预期的半浅蓝色......
我想使用转换为:
#define BackgroundColour "#497AC2"
procedure InitializeDataChecker;
...
begin
...
repeat
ShellExec('Open', ExpandConstant('{pf64}\ImageMagick-7.0.2-Q16\Convert.exe'),
ExpandConstant('-size ' + ScreenResolution + ' xc:' '{#BackgroundColour}' + ' -quality 100% "{tmp}\'+IntToStr(ImageNumber)+'-X.jpg"'), '', SW_HIDEX, ewWaitUntilTerminated, ErrorCode);
...
until FileExists(ExpandConstant('{tmp}\'+IntToStr(ImageNumber)+'.jpg')) = False;
...
end;
...
DataChecker := TForm.Create(nil);
{ ---HERE IT SHOULD BE RETURNED AS `$C27A49`--- }
DataChecker.Color := NewFunction({#BackgroundColour})
提前致谢。
function RGB(r, g, b: Byte): TColor;
begin
Result := (Integer(r) or (Integer(g) shl 8) or (Integer(b) shl 16));
end;
function WebColorStrToColor(WebColor: string): TColor;
begin
if (Length(WebColor) <> 7) or (WebColor[1] <> '#') then
RaiseException('Invalid web color string');
Result :=
RGB(
StrToInt('$' + Copy(WebColor, 2, 2)),
StrToInt('$' + Copy(WebColor, 4, 2)),
StrToInt('$' + Copy(WebColor, 6, 2)));
end;
您的 RGB 函数不起作用,因为 Pascal 脚本(与 Delphi 相反)似乎没有隐式地 convert/expand Byte
到 Integer
shl
操作。所以你必须明确地去做。
我想在 Inno Setup Pascal 脚本中将 HTML 十六进制颜色转换为 TColor
。
我尝试从 ColorToWebColorStr
,但我可能需要像 RGBToColor
这样的函数才能得到 TColor
.
示例:#497AC2
HTML 十六进制颜色的转换应返回为 TColor
$C27A49
.
输入应为 HTML 颜色字符串表示,输出应为 TColor
.
当我在 Inno Setup 中使用 VCL Windows
单元的以下功能时,TForm.Color
显示为红色。
const
COLORREF: TColor;
function RGB( R, G, B: Byte): COLORREF;
begin
Result := (R or (G shl 8) or (B shl 16));
end;
DataChecker.Color := RGB( 73, 122, 194);
我在TForm.Color
中期望的颜色是:
<html>
<body bgcolor="#497AC2">
<h2>This Background Colour is the Colour I expected instead of Red.</h2>
</body>
</html>
另外,我也想知道为什么这里返回的是红色(显示红色的表格)而不是预期的半浅蓝色......
我想使用转换为:
#define BackgroundColour "#497AC2"
procedure InitializeDataChecker;
...
begin
...
repeat
ShellExec('Open', ExpandConstant('{pf64}\ImageMagick-7.0.2-Q16\Convert.exe'),
ExpandConstant('-size ' + ScreenResolution + ' xc:' '{#BackgroundColour}' + ' -quality 100% "{tmp}\'+IntToStr(ImageNumber)+'-X.jpg"'), '', SW_HIDEX, ewWaitUntilTerminated, ErrorCode);
...
until FileExists(ExpandConstant('{tmp}\'+IntToStr(ImageNumber)+'.jpg')) = False;
...
end;
...
DataChecker := TForm.Create(nil);
{ ---HERE IT SHOULD BE RETURNED AS `$C27A49`--- }
DataChecker.Color := NewFunction({#BackgroundColour})
提前致谢。
function RGB(r, g, b: Byte): TColor;
begin
Result := (Integer(r) or (Integer(g) shl 8) or (Integer(b) shl 16));
end;
function WebColorStrToColor(WebColor: string): TColor;
begin
if (Length(WebColor) <> 7) or (WebColor[1] <> '#') then
RaiseException('Invalid web color string');
Result :=
RGB(
StrToInt('$' + Copy(WebColor, 2, 2)),
StrToInt('$' + Copy(WebColor, 4, 2)),
StrToInt('$' + Copy(WebColor, 6, 2)));
end;
您的 RGB 函数不起作用,因为 Pascal 脚本(与 Delphi 相反)似乎没有隐式地 convert/expand Byte
到 Integer
shl
操作。所以你必须明确地去做。