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 : ...
随机推荐
- 两数之和 Two Sum
给定一个整数数列,找出其中和为特定值的那两个数. 你可以假设每个输入都只会有一种答案,同样的元素不能被重用. 示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 n ...
- 大快DKhadoop开发环境安装常见问题与解决方案
2018年度国内大数据公司排名50强本月初榜单发布,榜单上看到大快搜索跻身50强,再看看他们做的DKHadoop发行版,的确还是蛮厉害的吧!最起码这款DKHadoop用起来确实在易用性方面要更好!Dk ...
- 【appium】根据accessibility_id定位元素
如何获得AccessibilityId 可以通过UIAutomatorViewer或者Appium Inspector获得.Accessibility ID在Android上面就等同于contentD ...
- git 不能拉取时,检查是不是被杀毒软件给干掉了
我这儿是 \Git\bin\sh.exe 被干掉了. 添加排除,并从隔离区中还原.
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
摘要 缺省情况下,ASP.NET应用程序以本机的ASPNET帐号运行,该帐号属于普通用户组,权限受到一定的限制,以保障ASP.NET应用程序运行的安全.但是有时需要某个ASP.NET应用程序或者程 ...
- yii framework config 可以被配置的项目
http://hi.baidu.com/lossless1009/item/990fdb33a52ffcf1e7bb7a4c <?php002 003 // 取消下行的注释,来定义一个路径别名0 ...
- JbossMiner 挖矿蠕虫分析 (转载)
前言 从2013年的诞生,到2016爆发,挖矿(MiningCryptocurrency) 的高回报率,使其成为了一把双刃剑.据外媒去年的统计,比特币的算力(Hash Rate)已在半年内翻了一翻. ...
- 小峰servlet/jsp(2)
一.jsp javaBean组件引入 <jsp:useBean id="实例化对象名称" scope="保存范围" class="类完整名称&q ...
- 6.后台验证码-session作用域
首先要有生成验证码图片和验证码文字的逻辑 package cn.bingou.util; import java.awt.Color; import java.awt.Font; import jav ...
- nginx的日志分析
1.到NGINX把日志DOWN下来2.用命令cat xxxx.log | egrep '10/Jul/2015:01:[4-5]|2015-07-10 02:0[0-57]'>xxxx2.log ...