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. javascript的循环使用

    学习网址: http://www.w3school.com.cn/js/js_loop_for.asp JavaScript 循环 如果您希望一遍又一遍地运行相同的代码,并且每次的值都不同,那么使用循 ...

  2. bzoj 4025 二分图——线段树分治+LCT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4025 线段树分治,用 LCT 维护链的长度即可.不过很慢. 正常(更快)的方法应该是线段树分 ...

  3. C语言实现<读取>和<写入> *.ini文件(转)

    原地址:https://blog.csdn.net/niha1993825jian/article/details/41086403 #include <stdio.h> #include ...

  4. bzoj4385 Wilcze doły

    Description 给定一个长度为n的序列,你有一次机会选中一段连续的长度不超过d的区间,将里面所有数字全部修改为0.请找到最长的一段连续区间,使得该区间内所有数字之和不超过p. Input 第一 ...

  5. PHP include 和 require 语句 (调用其他php文件进来的方法)

    PHP include 和 require 语句通过 include 或 require 语句,可以将 PHP 文件的内容插入另一个 PHP 文件(在服务器执行它之前). require 会生成致命错 ...

  6. Spring IOC - 控制反转(依赖注入) - 入门案例 - 获取对象的方式 - 别名标签

    1. IOC - 控制反转(依赖注入) 所谓的IOC称之为控制反转,简单来说就是将对象的创建的权利及对象的生命周期的管理过程交 由Spring框架来处理,从此在开发过程中不再需要关注对象的创建和生命周 ...

  7. Unity3D NGUI Sprite精灵动画

    NGUI 2.6.1下载: part1 part2 NGUI 实现Sprite精灵动画很简单: 1.先制作图像集合.打开NGUI菜单下Atlas Maker,选中切好的图片,点击Add/Update按 ...

  8. [转]NuGet 包升级

    Update-Package 在 NuGet 的命令控制台执行这个就会升级所有 NuGet 包,不带参数. 使用 VS2015 时,插件 Web Extension Pack 2015 和 Web.E ...

  9. Shell 定时发送邮件检查网站脚本/邮件正文

    #!/bin/bash ############################################################## # File Name: check_http.s ...

  10. 1115 Counting Nodes in a BST (30 分)

    1115 Counting Nodes in a BST (30 分) A Binary Search Tree (BST) is recursively defined as a binary tr ...