delphi 颜色转换函数总结
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 颜色转换函数总结的更多相关文章
- Delphi 颜色转换
http://files.cnblogs.com/xe2011/StringToColor.rar unit Unit1; interface uses Windows, Messages, SysU ...
- PHP函数篇详解十进制、二进制、八进制和十六进制转换函数说明
PHP函数篇详解十进制.二进制.八进制和十六进制转换函数说明 作者: 字体:[增加 减小] 类型:转载 中文字符编码研究系列第一期,PHP函数篇详解十进制.二进制.八进制和十六进制互相转换函数说明 ...
- Delphi实现AnsiString与WideString的转换函数 转
Delphi实现AnsiString与WideString的转换函数 分类: Delphi2013-01-26 16:23 460人阅读 评论(0) 收藏 举报 [delphi] view plain ...
- delphi 金额大小写转换函数
{*------------------------------------------------ 金额大小写转换函数 @author 王云盼 @version V1506.01 在delphi7测 ...
- Delphi 使用之函数
函数由一句或多句代码组成,可以实现某个特定的功能.使用函数可以使代码更加易读.易懂,加快编程速度及减少重复代码.过程与函数类似,过程与函数最重要的区别在于,过程没有返回值,而函数能有返回值. ...
- Delphi 常用API 函数
Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小 AnyPopup 判断屏幕上是否存在任何弹出式窗口 ArrangeIconic ...
- delphi 颜色 引用http://www.cnblogs.com/del/archive/2008/02/19/1073568.html
颜色名称 颜色效果 Hex HTML clBlack $000000 #000000 clMaroon $000080 #800000 clGreen $008000 #00800 ...
- Delphi 常用API 函数列表
Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWi ...
- Delphi常用系统函数总结
Delphi常用系统函数总结 字符串处理函数 Unit System 函数原型 function Concat(s1 [, s2,..., sn]: string): string; 说明 与 S : ...
随机推荐
- Qt treewidget样式的自定义(转)
这个treewidget样式真是写得让人心碎,主因是那个天杀的表头,真是块古里古怪的硬骨头,令人抓狂,一直找不到给表头设定背景图的方法,让我一度决定弃用tree. 后来表头的属性找到了,下拉条又找不到 ...
- C#连接Oracle数据库的连接字符串
来源:http://blog.csdn.net/superhoy/article/details/8108037 两种方式:1.IP+SID方式 2.配置链接方式 1..IP+SID方式 DbHelp ...
- c# 与 java 语法异同
Java and C# ComparisonThis is a quick reference guide to highlight some key syntactical differences ...
- Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析
转自:http://www.uml.org.cn/mobiledev/201211221.asp 今天,我着重讲解下如下三个内容: measure过程 WRAP_CONTENT.MATCH_PAREN ...
- HttpUrlConnection使用详解--转
http://blog.csdn.net/fightingXia/article/details/71775516 一,HttpURLconnection的介绍 在Android开发中网络请求是最常用 ...
- 基于jQuery的表单操作
1,文本框的聚焦和失焦 在对文本框进行操作时,通常为了提升用户体验,是用户的操作得到及时的反馈,会在文本框获得焦点时,让其颜色改变,然后在失去焦点时恢复为原来的样式,一般情况下,我们可以通过css的伪 ...
- appium+python自动化42-微信公众号
前言 本篇介绍如何在微信公众号上自动化测试,以操作我的个人公众号:yoyoketang为例,没关注的,先微信关注了,再跟着操作 环境准备: python 3.6 appium 1.7以上版本 微信6. ...
- sublime text 3 3143
下载链接:https://download.sublimetext.com/Sublime%20Text%20Build%203143%20x64%20Setup.exe 注册信息:sublime t ...
- (转!)大话websocket
邪正看眼鼻,真假看嘴唇,功名看气概,富贵看精神. ---曾国藩<冰鉴> 转自https://www.cnblogs.com/fuqiang88/p/5956363.html 原文http: ...
- javascript创建对象之工厂模式(一)
工厂模式在软件工程里面是一种比较常见的设计模式了.这种模式抽象了创建具体对象的过程. 上代码: function createHuman(name,sex) { var obj = new Objec ...