How to convert hex colour values into Delphi formatted ones #140
Question
Is there a routine that can take a hex color value and convert it to a
Delphi formatted value like: "Cornsilk1 Cornsilk1 255 248 220
#FFF8DC" into $00DCF8FF?
Untested:
function Swap32(aLong: Longint): Longint; assembler; asm BSWAP eax end; function HexColorToColor(HexColor: string): TColor; {input: '#FFF8DC' -> output $DCF8FF as TColor, use IntTohex to convert output to string again if needed} begin Assert(Length(hexcolor)) > 1); Assert(hexcolor[1] = '#'); hexcolor[1] := '$'; Result := Swap32(StrToInt(hexcolor)); end;
Original resource: | The Delphi Pool |
---|---|
Author: | Peter Below |
Added: | 2009/11/06 |
Last updated: | 2009/11/06 |