Delphi里面的颜色和HTML的颜色互转

function HtmlToColor(HColor: Integer): Integer;
var
sColorMsg: string;
srValue, sgValue, sbValue: string;
irValue, igValue, ibValue: Integer;
begin
sColorMsg := IntToHex(HColor, 6);
srValue := '$' + Copy(sColorMsg, 1, 2);
sgValue := '$' + Copy(sColorMsg, 3, 2);
sbValue := '$' + Copy(sColorMsg, 5, 2);
irValue := StrToInt(srValue);
igValue := (StrToInt(sgValue) shl 8);
ibValue := (StrToInt(sbValue) shl 16);
Result := irValue + igValue + ibValue;
end;

function ColorToHtml(DColor:TColor):string;
var
tmpRGB : TColorRef;
begin
tmpRGB := ColorToRGB(DColor) ;
Result:=Format('#%.2x%.2x%.2x',
[GetRValue(tmpRGB),
GetGValue(tmpRGB),
GetBValue(tmpRGB)]) ;
end; {function ColorToHtml}

posted @ 2012-09-19 00:26  我为硬件而狂  阅读(387)  评论(0编辑  收藏  举报