Autor Beitrag
Jean-Christoph
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Fr 29.09.06 08:27 
Wer kann mir bitte mal unter die Arme greifen?

Wie kann ich aus einem TColor Wert aus dem ColorDialog
eine Hexzahl (z.B. #009000) machen, die dem originalen
Farbwert auch noch entspricht?

Vielen Dank!
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Fr 29.09.06 08:38 
ausblenden Delphi-Quelltext
1:
 showmessage(inttohex(clBlue,6));					

end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Jean-Christoph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Fr 29.09.06 09:27 
Danke erstmal für die schnelle Antwort.

Das Problem ist, das aus z.B. clYellow #00FFFF (türkis) wird.
clGreen wird #0E9B48 bleibt Grün?
Jean-Christoph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Fr 29.09.06 09:42 
Ich möchte kurz erklären was ich bewerkstelligen will.
Es geht darum aus einem Text eine Html-Seite zu erzeugen.
Der Anwender sucht sich die Farben der Scrollbalken in meinem Delphi5 Prog aus und das Programm generiert den Html Text.

WriteNative('<style type="text/css">BODY '
+'{SCROLLBAR-FACE-COLOR: #'+inttohex(clYellow,6)+#59

direkt eingesetzt für Testzwecke (clYellow wird Türkis)

+'{SCROLLBAR-FACE-COLOR: #'+inttohex(StringtoColor(dbf.aktion.FieldByNAme('sbvg').AsString),6)+#59 (clYellow wird Türkis)
so soll es später aussehen, der Farbwert ist als String gespeichert (entspricht dem Int Wert des Colordialoges)
+'}'
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Fr 29.09.06 09:44 
user profile iconJean-Christoph hat folgendes geschrieben:
Danke erstmal für die schnelle Antwort.

Das Problem ist, das aus z.B. clYellow #00FFFF (türkis) wird.
clGreen wird #0E9B48 bleibt Grün?


Das liegt daran, das TColor die Farben nicht in der Reihenfolge RGB, sondern BGR enthält. RGB bekommst du mit

ausblenden Delphi-Quelltext
1:
IntToHex(farbe and $000000FF, 2) + IntoToHex((farbe and $0000FF00) shr 8, 2) + IntToHex((farbe and $00FF0000) shr 16, 2)					


Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Fr 29.09.06 09:58 
OK, dann vielleicht so !

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function ColorToHex (color : TColor) : String;
var r,g,b : Byte;
begin
  r := GetRValue(color);
  g := GetGValue(color);
  b := GetBValue(color);
  Result := Inttohex(r,2) + Inttohex(g,2) + Inttohex(b,2);
end;
...

ShowMessage(ColorToHex(clYellow));



[Edit] Neue function eingefügt !

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Jean-Christoph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Fr 29.09.06 10:24 
Vielen Dank Euch beiden. Es geht.