Thema: Delphi RGBToHex und umgekehrt

Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

RGBToHex und umgekehrt

  Alt 18. Mai 2019, 10:05
Ich konvertiere RGB zu Hex.

Delphi-Quellcode:
function TSkinEngine.RGBtoHEX(ColrRGB: ColorRef): string;
var
 R, G, B: Byte;
begin

  R:= GetRValue(ColrRGB);
  G:= GetGValue(ColrRGB);
  B:= GetBValue(ColrRGB);

  Result:= Format('$%.2x%.2x%.2x', [R, G, B]);
end;

UseColor := RGBtoHEX(RGB(11,37,86)); // := $0B2556;

jetzt umgekehrt.
Delphi-Quellcode:
    if UseColor > 'then
    begin
      R := Byte(StrToInt('$' + Copy(UseColor, 3, 2)));
      G := Byte(StrToInt('$' + Copy(UseColor, 5, 2)));
      B := Byte(StrToInt('$' + Copy(UseColor, 7, 2)));
    end
Die Werte von R, G, B sind aber jetzt komplett anders. Was mache ich falsch?
Delphi-Quellcode:
R := 178;
G := 85;
B := 6;
gruss
  Mit Zitat antworten Zitat