颜色之间的转换:RGB<--->网页颜色<--->delphi颜色(10分)

  • 主题发起人 主题发起人 laohe
  • 开始时间 开始时间
L

laohe

Unregistered / Unconfirmed
GUEST, unregistred user!
颜色之间的转换:RGB<--->网页颜色<--->delphi颜色
 
{由于Delphi的RGB方式与HTML的不同,所以需要转换}
function ColorToHTMLColor(
SourceColor: WideString): WideString;
var
i : Integer;
strTmp : String;
begin
SourceColor := Trim(SourceColor);
if Pos('$',SourceColor) <= 0 then
begin
Result := Copy(SourceColor,3,Length(SourceColor)-2);
Exit;
end;
Result := '';
if Trim(SourceColor) ='' then Exit;
Result := '#';
For i := 0 to 2 do
begin
StrTmp := Copy(SourceColor,Length(SourceColor)-1,2);
Delete(SourceColor,Length(SourceColor)-1,2);
Result := Result + StrTmp;
end;
end;
 
html转为delphi就不好转.

delphi转html颜色的以前有看过.
 
照我的试试?
应该很好做得!
思想将“#”-〉“$”

最后两位-〉Delphi的头两位
依次往上来就行了!
 
怎么没有接着回答,我知道分少.
 
你不会自己动手写一下吗?
这不是很简单的事情!
 
// *****************************************************************************
// HtmlToTColor: 33FFBB -> TColor
// *****************************************************************************
function HtmlToTColor(sColor : string ): integer;
begin
try
Result := RGB(
{ get red value }
StrToInt( '$'+Copy( sColor, 2, 2 ) ),
{ get green value }
StrToInt( '$'+Copy( sColor, 4, 2 ) ),
{ get blue value }
StrToInt( '$'+Copy( sColor, 6, 2 ) )
);
except
raise Exception.Create(sColor+': Error html COLOR string!');
end;
end;
 
接受答案了.
 
后退
顶部