unit UColor;

interface

uses windows, sysutils, classes, graphics;

function HexToInt(Hexa: String): LongWord;

function ColorToString(color: TColor): String;

function WebColorToDelphiTColor(webcolor: String): TColor;
function HexToTColor(sHtmlColor: String): TColor; function HexIntColorToHtmlColor(c: Integer): String;
function TColorToWebColor(DColor: TColor): String;
function HexStrColorToHtmlColor(s: String): String; implementation function HexToInt(Hexa: String): LongWord;
const
ValoresHexa: array['A'..'F'] of Integer = (, , , , , );
var
nDecimal: LongWord;
nIndex: Byte;
begin
nDecimal := ;
Hexa := Uppercase(Hexa);
for nIndex := Length(Hexa) downto do
if Hexa[nIndex] in [''..''] then
nDecimal := nDecimal + StrToInt(Hexa[nIndex]) *
Trunc(Exp((Length(Hexa) - nIndex) * ln()))
else
nDecimal := nDecimal + ValoresHexa[Hexa[nIndex]] *
Trunc(Exp((Length(Hexa) - nIndex) * ln()));
Result := nDecimal;
end; function ColorToString(color: TColor): String;
var
r, g, b: Byte;
begin
r := GetRValue(color);
g := GetgValue(color);
b := GetbValue(color);
Result := '$' + IntToHex(TColor(RGB(r, g, b)), );
end; function WebColorToDelphiTColor(webcolor: String): TColor;
var
a: array [..] of Byte;
b: array[..] of Byte;
begin
{
rgb颜色,就是用6位16进制数去表示的颜色
RGB的颜色是从低位向高位存储,而TCOLOR正好与之相反,
例如
RGB : F1F2FE
Tcolor: $00FEF2F1
}
Integer(a) := HexToInt(webcolor);
if a[] = then
begin
b[] := a[];
b[] := a[];
b[] := a[];
b[] := ;
end
else
begin
b[] := a[];
b[] := a[];
b[] := a[];
b[] := a[];
end;
Result := TColor(b);
end; function HexToTColor(sHtmlColor: String): TColor;
begin
//与上面 WebColorToDelphiTColor 的功能相同
if pos('#', sHtmlColor) = then
sHtmlColor := copy(sHtmlColor, , length(sHtmlColor)); Result :=
RGB(StrToInt(# + Copy(sHtmlColor, , )),
StrToInt(# + Copy(sHtmlColor, , )), StrToInt(# + Copy(sHtmlColor, , )));
end; function HexIntColorToHtmlColor(c: Integer): String;
var
R, G, B: Byte;
begin
R := c and $FF;
G := (c shr ) and $FF;
B := (c shr ) and $FF;
Result := # + Format('%.2x%.2x%.2x', [R, G, B]);
end; {从十六进制字符串转换到 Html 颜色}
function HexStrColorToHtmlColor(s: String): String;
var
i: Integer;
R, G, B: Byte;
begin
i := StrToInt(s);
R := i and $FF;
G := (i shr ) and $FF;
B := (i shr ) and $FF;
Result := # + Format('%.2x%.2x%.2x', [R, G, B]);
end; function TColorToWebColor(DColor: TColor): String;
var
tmpRGB: TColorRef;
begin
tmpRGB := ColorToRGB(DColor);
Result := Format('#%.2x%.2x%.2x', [GetRValue(tmpRGB),
GetGValue(tmpRGB), GetBValue(tmpRGB)]);
end; end.

delphi 颜色转换函数总结的更多相关文章

  1. Delphi 颜色转换

    http://files.cnblogs.com/xe2011/StringToColor.rar unit Unit1; interface uses Windows, Messages, SysU ...

  2. PHP函数篇详解十进制、二进制、八进制和十六进制转换函数说明

    PHP函数篇详解十进制.二进制.八进制和十六进制转换函数说明 作者: 字体:[增加 减小] 类型:转载   中文字符编码研究系列第一期,PHP函数篇详解十进制.二进制.八进制和十六进制互相转换函数说明 ...

  3. Delphi实现AnsiString与WideString的转换函数 转

    Delphi实现AnsiString与WideString的转换函数 分类: Delphi2013-01-26 16:23 460人阅读 评论(0) 收藏 举报 [delphi] view plain ...

  4. delphi 金额大小写转换函数

    {*------------------------------------------------ 金额大小写转换函数 @author 王云盼 @version V1506.01 在delphi7测 ...

  5. Delphi 使用之函数

    函数由一句或多句代码组成,可以实现某个特定的功能.使用函数可以使代码更加易读.易懂,加快编程速度及减少重复代码.过程与函数类似,过程与函数最重要的区别在于,过程没有返回值,而函数能有返回值.     ...

  6. Delphi 常用API 函数

    Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小 AnyPopup 判断屏幕上是否存在任何弹出式窗口 ArrangeIconic ...

  7. delphi 颜色 引用http://www.cnblogs.com/del/archive/2008/02/19/1073568.html

    颜色名称   颜色效果   Hex HTML clBlack   $000000 #000000 clMaroon   $000080 #800000 clGreen   $008000 #00800 ...

  8. Delphi 常用API 函数列表

    Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWi ...

  9. Delphi常用系统函数总结

    Delphi常用系统函数总结 字符串处理函数 Unit System 函数原型 function Concat(s1 [, s2,..., sn]: string): string; 说明 与 S : ...

随机推荐

  1. AppBox下调用HighCharts画曲线

    例子见本博文件下载. 注意                xAxis: {                    categories: [<%= xAxisCategories %>], ...

  2. iPhone激活策略知识讲解:官方解锁和黑解

    iPhone激活策略知识讲解:官方解锁和黑解 [复制链接]     LEECHY 该用户从未签到 1372 XY豆 438 帖子 440 贡献 苹果花 积分 2250 发消息 电梯直达 楼主    发 ...

  3. datacolumn 表达式 除数为0

    dt.columns.add("avgp",typeof(decimal),"IIF(qty=0,0,price/qty)")

  4. 2013-7-27 802.1X学习

    最近搭了企业级加密的server 2003服务器,教程完全google,无任何自主创新.折腾了一周,总算搞定了,同时也验证了server 2003下的TLS和PEAP0加密算法是正常的. 至于搭建se ...

  5. javascript的防篡改对象之preventExtensions()方法

    js在默认情况下,所有的对象都是可扩展的.这也是让很多开发人员头特疼的问题.因为在同一环境中,一不小心就会发生修改了不必要的对象,而自己却不知道. 在ECMAScript5可以解决这种问题了. pre ...

  6. ASP.NET基于Redis的Provider库

    因为session基于本地cache,以前我们自己写分布式缓存,或者数据库存储,或者cookie加密存储,来保存用户状态信息,但较少的直接通过创建一个继承 SessionStateStoreProvi ...

  7. 常用模块:os模块,logging模块等

    一    os模块 那么作为一个常用模块,os模块是与操作系统交互的一个模块. 那么os模块中我们常用的一般有以下几种: os.listdir('dirname') 以列表的形式列出指定目录下的所有文 ...

  8. orm 小结

     1. 销售注册,登录系统  - 用户表  2.销售添加客户信息,成为销售的私户  - 客户表    3. 销售固定时间跟进客户  - 跟进记录表 4. 客户报名  - 报名记录表  - 班级表(必须 ...

  9. VSCode编辑器编写Python代码

    如何用VSCode愉快的写Python https://code.visualstudio.com/   在学习Python的过程中,一直没有找到比较趁手的第三方编辑器,用的最多的还是Python自带 ...

  10. uva-10112-计算几何

    题意:给你一些点,求这些点组成的三角形面积最大,而且三角形内不能包含其他点 #include <iostream> #include <math.h> #include< ...