Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 将4字节十六进制颜色转换为RGB_Delphi_Vcl - Fatal编程技术网

Delphi 将4字节十六进制颜色转换为RGB

Delphi 将4字节十六进制颜色转换为RGB,delphi,vcl,Delphi,Vcl,我在尝试将4字节十六进制格式的颜色转换为RGB格式时遇到了一个问题,最大的问题是4字节十六进制颜色的前两个字符,我不知道如何转换。我有一个十六进制:$16750899,需要转换成RGB 0..255,0..255,0..255的格式,你可以在embarcadero docwiki上找到 如文件所述: [……] 如果将TColor指定为特定的4字节十六进制数 [……] 低三个字节分别表示蓝色、绿色和红色的RGB颜色强度 然后,你可以看看这个 我希望这些链接可以帮助您。将十六进制字符串转换为如下数值

我在尝试将4字节十六进制格式的颜色转换为RGB格式时遇到了一个问题,最大的问题是4字节十六进制颜色的前两个字符,我不知道如何转换。我有一个十六进制:$16750899,需要转换成RGB 0..255,0..255,0..255的格式,你可以在embarcadero docwiki上找到

如文件所述:

[……]

如果将TColor指定为特定的4字节十六进制数

[……]

低三个字节分别表示蓝色、绿色和红色的RGB颜色强度

然后,你可以看看这个


我希望这些链接可以帮助您。

将十六进制字符串转换为如下数值:

var
  Color: Integer;
....
Color := StrToInt(str);
function GetAValue(rgba: Integer): Byte;
begin
  Result := Byte(rgb shr 24);
end;
procedure ExtractColorChannels(rgba: Integer; out r, g, b, a: Byte);
begin
  r := Byte(rgba);
  g := Byte(rgba shr 8);
  b := Byte(rgba shr 16);
  a := Byte(rgba shr 24);
end;
您的值有四个通道,因此假设第四个通道为alpha。使用GetRValue、GetGValue和GetBValue选择颜色通道。按如下方式获取alpha通道:

var
  Color: Integer;
....
Color := StrToInt(str);
function GetAValue(rgba: Integer): Byte;
begin
  Result := Byte(rgb shr 24);
end;
procedure ExtractColorChannels(rgba: Integer; out r, g, b, a: Byte);
begin
  r := Byte(rgba);
  g := Byte(rgba shr 8);
  b := Byte(rgba shr 16);
  a := Byte(rgba shr 24);
end;
或者您可以像这样一次将它们全部解包:

var
  Color: Integer;
....
Color := StrToInt(str);
function GetAValue(rgba: Integer): Byte;
begin
  Result := Byte(rgb shr 24);
end;
procedure ExtractColorChannels(rgba: Integer; out r, g, b, a: Byte);
begin
  r := Byte(rgba);
  g := Byte(rgba shr 8);
  b := Byte(rgba shr 16);
  a := Byte(rgba shr 24);
end;
然后你可以写:

var
  r, g, b, a: Byte;
....
ExtractColorChannels(StrToInt(str), r, g, b, a);
对于您输入的“$16750899”,这将产生以下通道:

Alpha: $16 Blue: $75 Green: $08 Red: $99
我们也不知道如何转换它。这取决于输入格式。你知道那是什么吗?阿格?BGRA?RGBA?帕尔格?等等?@J。。。我没有ideia,只知道这是一个TColor格式源格式是TColor?目的地格式是什么?您想要Windows RGB格式吗?还是其他RGB格式?您想要独立的颜色通道吗?十六进制不是颜色,它只是格式化。@William Nope。就像我说的十六进制不是颜色。您可以使用相同的十六进制值,但如果基础格式为ARGB color,则它包含的颜色将与格式为RGBA的颜色截然不同。你没有说你的颜色是从哪里来的,是什么格式的。四字节十六进制颜色,如果有许多不同的品种。你有哪一个?我们只能胡乱猜测那一部分。