Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi HTML Code Farben verwenden (https://www.delphipraxis.net/8360-html-code-farben-verwenden.html)

joeyjmr 3. Sep 2003 09:37


HTML Code Farben verwenden
 
ich hab da mal ne frage wie kann man in delphi7 htmlcode farben verwenden?? muss man da irgendwas beachten??

Sanchez 3. Sep 2003 09:45

Re: HTML Code Farben verwenden
 
hallo,

ich hab da ein Paar Codezeilen aufgeschnappt die, glaube ich, dass erledigen, was du brauchst

Delphi-Quellcode:
uses SysUtils, Graphics;
// converts a color to an html color string
// clRed => #FF0000
function Sto_ColorToHtml(const Color: TColor): String;
var
  iRgb: Longint;
  iHtml: Longint;
begin
  // convert system colors to rgb colors
  iRgb := ColorToRGB(Color);
  // change BBGGRR to RRGGBB
  iHtml := ((iRgb and $0000FF) shl 16) or // shift red to the left
           ( iRgb and $00FF00) or        // green keeps the place
           ((iRgb and $FF0000) shr 16);  // shift blue to the right
  // create the html string
  Result := '#' + IntToHex(iHtml, 6);
end;

// converts an html color string to a color,
// can raise an EConvertError exception
// #0000FF -> clBlue
function Sto_HtmlToColor(Color: String): TColor;
var
  iHtml: Longint;
begin
  // remove the preceding '#'
  if (Length(Color) > 0) and (Color[1] = '#') then
    Delete(Color, 1, 1);
  // convert html string to integer
  iHtml := StrToInt('$' + Color);
  // change RRGGBB to BBGGRR
  Result := ((iHtml and $FF0000) shr 16) or // shift red to the right
            ( iHtml and $00FF00) or        // green keeps the place
            ((iHtml and $0000FF) shl 16);  // shift blue to the left
end;
grüße, daniel

Alexander 3. Sep 2003 15:44

Re: HTML Code Farben verwenden
 
Delphi-Quellcode:
function ConvertToHtmlColor(Col : TColor): string;
var
s : string;
begin
 s := IntToHex(ColorToRgb(col),6);
  s := Copy(s,5,2) + Copy(s,3,2) + Copy(s,1,2);
   Result := Format('#%s', [s]);
end;

function ConvertToRGBColor(Col : TColor): string;
var i: integer;
begin
  i := ColorToRGB(Col);
result := inttostr(GetBValue(i))+inttostr(GetGValue(i))+inttostr(GetRValue(i));
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:08 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz