Autor Beitrag
Frankieboy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65



BeitragVerfasst: Fr 22.01.10 12:08 
Hallo,

ich habe ein Problem:

Ich habe einen RGB-Farbwert in den Variablen Red, Green, Blue (Integer).
Wie ändere ich den Farbwert in den Variablen in einen Wert vom Typ TColor?

Grüße,

Frank
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Fr 22.01.10 12:34 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
function RGB2TColor(const R, G, B: Byte): Integer;
begin
  // convert hexa-decimal values to RGB
  Result := R + G shl 8 + B shl 16;
end;


procedure TColor2RGB(const Color: TColor; var R, G, B: Byte);
begin
  // convert hexa-decimal values to RGB
  R := Color and $FF;
  G := (Color shr 8and $FF;
  B := (Color shr 16and $FF;
end;

//Anwendungsbeispiel:
var
  R, G, B: Byte;
  Color: TColor;
begin
  Color := clBtnFace;
  TColor2RGB(Color, R, G, B);
  R := 114;
  G := 225;
  B := 0;
  Color := RGB2TColor(R, G, B);
end;
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 22.01.10 12:42 
Es gibt dafür aber auch fertige Funktionen von Delphi. Als da wären RGB (wie bei dir RGB2TColor, nur natürlich mit or statt +), GetRValue, GetGValue, GetBValue, sowie ColorToRGB um die Farbe zuerst in einen RGB-Wert umzuwandeln. Was du nämlich vergessen hast ist, dass TColor nicht immer nur RGB-Werte enthält, sondern auch Systemfarben enthalten kann.