![]() |
Re: hex-codes in RGB werte und umgekehrt??
Zitat:
genau, als Parameter brauchst du der Funktion aber nicht unbedingt Hex werte übergeben. Zitat:
Delphi-Quellcode:
if Colordialog1.Execute then
self.Color:= Colordialog1.Color; |
Re: hex-codes in RGB werte und umgekehrt??
Hier mal 2 Funktionen für dich, die ich selbst auch benutze:
Delphi-Quellcode:
function HtmlColorToColor(AHtmlColor: string): TColor;
begin Delete(AHtmlColor, 1, 1); Result := StrToInt('$' + Copy(AHtmlColor, 5, 2) + Copy(AHtmlColor, 3, 2) + Copy(AHtmlColor, 1, 2)); end; function ColorToHTMLColor(Color: TColor): String; begin Color := ColorToRGB(Color); Result := Format('#%.2x%.2x%.2x', [GetRValue(Color),GetGValue(Color), GetBValue(Color)]); end; |
Re: hex-codes in RGB werte und umgekehrt??
ich hab jetzt noch ein problem:
bei der umwandlung von hex in rgb muss ja die Hexfarbe vom typ Cardinal sein... wie kann ich einen Inhalt eines Edit's (typ = String) in den typ Cardinal umwandeln?? hier mal mein hex in RGB umwandel-Qelltext: Bitte auf kommentare antworten!!
Delphi-Quellcode:
Und hier mein RGB in Hex umwandel - quelltext:
procedure TForm1.Umwandeln1Click(Sender: TObject);
begin Hex1 := Hexcolor.Text; Col := Hex1; // Hier von String in Cardinal umwandeln!!!! RGBan.Caption := Format('%d %d %d',[GetBValue(Col), GetGValue(Col),GetRValue(Col)]); // Muss man hier // auch was wieder in einen String umwandeln??? Panel1.Color:= RGB(GetBValue(Col),GetGValue(Col),GetRValue(Col)); // Funktioniert das so??? end; Bitte auch auf Kommentare antworten!!
Delphi-Quellcode:
procedure TForm1.Umwandeln2Click(Sender: TObject);
begin R := ran.Text; //String G := gan.Text; //String B := ban.Text; //String Hexcolor2.Caption := Format('#%.2x%.2x%.2x', [R,G,B]); // R,G,B hier Float oder Integer sein müssen ??? end; |
Re: hex-codes in RGB werte und umgekehrt??
Zitat:
![]()
Delphi-Quellcode:
procedure TForm1.Umwandeln1Click(Sender: TObject);
begin Hex1 := Hexcolor.Text; Col := Stringtocolor('$00FF0088'); // Hier von String in Cardinal umwandeln!!!! RGBan.Caption := Format('%d %d %d',[GetBValue(Col), GetGValue(Col),GetRValue(Col)]); // Muss man hier // auch was wieder in einen String umwandeln??? Mht Format doch ...? Panel1.Color:= Col; // Funktioniert das so??? -> nein, auch einfacher ;-) end;
Delphi-Quellcode:
procedure TForm1.Umwandeln2Click(Sender: TObject);
begin R := ran.Text; //String G := gan.Text; //String B := ban.Text; //String Hexcolor2.Caption := Format('#%.2x%.2x%.2x', [R,G,B]); // R,G,B hier Float oder Integer sein müssen ??? Weder noch - es müssen imho Byte-Werte sein (Ganzzahlig bis 255) end; |
Re: hex-codes in RGB werte und umgekehrt??
danke für die antwort, du hast mir perfekt geholfen... danke
noch eine frage: wie (mit welcher funktion) wandelt man von String in Byte um???
Delphi-Quellcode:
könntet ihr mir nochmal schnell helfen?? danke...
procedure TForm1.Umwandeln2Click(Sender: TObject);
begin R := ran.Text; G := gan.Text; B := ban.Text; Hexcolor2.Caption := Format('#%.2x%.2x%.2x', [R,G,B]); Panel2.Color := RGB (R, G, B); // hier brauche ich bei R, G, B Bytes ... keine Strings wie??? end; |
Re: hex-codes in RGB werte und umgekehrt??
Kann mir Bitte einer helfen???????????????????????????
Ich bräuchte es dringend... |
Re: hex-codes in RGB werte und umgekehrt??
Hi,
du musst aber darauf achten, dass gültige Zahlen in den Feldern sind und dass der Bereich der Zahlen zwischen 0..255 liegt.
Delphi-Quellcode:
RGB(StrToInt(R), StrToInt(G), StrToInt(B));
|
Re: hex-codes in RGB werte und umgekehrt??
Hallo Max,
du liest scheinbar die Beiträge in deinem Thread nicht sehr genau. In Beitrag #12 hättest du sonst schon die Funktion StrToInt() kennen gelernt und die Funktion StringToColor() stand bereits in Beitrag #2 - vor zwei Tagen ... Nachdenkliche Grüße |
Re: hex-codes in RGB werte und umgekehrt??
Zitat:
aber ich habe nicht gewusst, das die funktionen StrToInt und StrToColor auch zum umwandeln in Bytes benützt werden können bin halt noch ein anfänger... :roll: danke bitsetter für die antwort //Edit: Jetzt funzt alles perfekt, ausser das:
Delphi-Quellcode:
er meldet das #%.2x% ein ungültiges Format ist!
procedure TForm1.Umwandeln2Click(Sender: TObject);
begin try R := ran.Text; G := gan.Text; B := ban.Text; Hexcolor2.Caption := Format('#%.2x%.2x%.2x', [R,G,B]); Panel2.Color := RGB(StrToInt(R), StrToInt(G), StrToInt(B)); except ShowMessage('Ungülte Farbenwerte! Bitte überprüfen!'); end; end; was muss ich ändern? |
Re: hex-codes in RGB werte und umgekehrt??
Liste der Anhänge anzeigen (Anzahl: 2)
sry mein 2 post aber:
ich hab noch ein problem!
Delphi-Quellcode:
wenn ich 95CAFF für Hex1 nehme: kommt als RGB 255 202 149 // es muss 149 202 255 lauten!! Und das Pnael ziegt orange an, obwohl es hellblau ist! (siehe bug1.bmp)
procedure TForm1.Umwandeln1Click(Sender: TObject);
begin try Hex1 := '$'+Hexcolor.Text; Col := StringToColor(Hex1); RGBan.Caption := Format('%d %d %d',[GetRValue(Col), GetGValue(Col),GetBValue(Col)]); Panel1.Color:= Col; except ShowMessage ('Ungültige Farbenwerte! Bitte überprüfen!') end; end; wenn ich DB1B44 nehme kommt: 68 27 219 // Jetzt richtig ausser das es 189 statt 219 heißen muss! Und das Panel zeigt dunkelblau an, obwohl es dunkelrot ist!! (siehe bug2.bmp) WARUM??? |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:30 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz