Einzelnen Beitrag anzeigen

Benutzerbild von mirage228
mirage228

Registriert seit: 23. Mär 2003
Ort: Münster
3.750 Beiträge
 
Delphi 2010 Professional
 
#2

Re: Farbkonvertierung scheint fehlerhaft!?

  Alt 7. Nov 2004, 08:14
Hi,

versuche es mal mit dieser Funktion:

Delphi-Quellcode:
function HTML2Color(const HTML: String): Integer;
var
  Offset: Integer;
begin
  if HTML[1] = '#then
    Offset := 1
  else
    Offset := 0;
  Result :=
    Integer(StrToInt('$' + Copy(HTML, Offset + 1, 2))) +
    Integer(StrToInt('$' + Copy(HTML, Offset + 3, 2))) shl 8 +
    Integer(StrToInt('$' + Copy(HTML, Offset + 5, 2))) shl 16;
end;
Edit: Und noch die Umkehrfunktion:
Delphi-Quellcode:
function Color2HTML(Color: TColor): String;

  function Swap(Color: TColor): TColor;
  begin
    Result :=
      Color and $FF0000 shr 16 +
      Color and $00FF00 +
      Color and $0000FF shl 16;
  end;

begin
  try
    Result := '#' +
      IntToHex(Byte(Color), 2) +
      IntToHex(Byte(Color shr 8), 2) +
      IntToHex(Byte(Color shr 16), 2);
  except
    Result := '#000000';
  end;
end;
mfG
mirage228
David F.

May the source be with you, stranger.
PHP Inspection Unit (Delphi-Unit zum Analysieren von PHP Code)
  Mit Zitat antworten Zitat