您的位置:首页 > 编程语言 > Delphi

HTML Color To Delphi TColor

2016-10-10 10:00 183 查看
HTML Color 采用十六进制表示颜色,其格式为RGB,而Tcolor的格式是GBR。如果把HTML颜色转为Tcolor,需要转换其格式。

比如: HTML Color: #123456

    转为Tcolor,则为:$563412, 把其转为Integer值,即为Tcolor值。

function TForm1.htmlColor2color( hColor : string ) : Integer;
var
s, c : string;
begin
s := hColor.Trim;
if ( s.Chars[ 0 ] ).IsNumber then
s := s.PadLeft( 6, '0' )
else
s := s.Substring( 1 ).PadLeft( 6, '0' );
// html color : rgb tcolor : gbr
Result := ('$' + s.Substring( 4, 2 ) + s.Substring( 2, 2 ) + s.Substring( 0, 2 )).ToInteger;
end;

以上在 Delphi Berlin 10.1 测试通过。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HTML Colot To Tcolor