RGB(16进制)_转_TColor

本文详细介绍了Windows编程中COLORREF与TColor颜色值之间的转换方法,包括RGB颜色值到TColor的转换函数RGBToColor,以及TColor到RGB颜色值的提取过程。

ZC:内存中 COLORREF就是一个DWORD(从定义"COLORREF = DWORD;"就可以看出来),但是 具体的byte R/G/B 的位置是怎么方式的?

ZC:Windows.pas 中 函数 function RGB(r, g, b: Byte): COLORREF;

 

1、

function RGBToColor(R,G,B: byte): TColor;
begin
  Result := B Shl 16 or G  shl 8 or R;
end;

 

2、TColor 转 R/G/B

procedure ExtractRGB(const Color: Graphics.TColor; out Red, Green, Blue: Byte);
var
  RGB: Windows.TColorRef; // RGB equivalent of given Colour
begin
  RGB := Graphics.ColorToRGB(Color);  // ensures system Colours are converted
  Red := Windows.GetRValue(RGB);
  Green := Windows.GetGValue(RGB);
  Blue := Windows.GetBValue(RGB);
end;

 

3、转的:

// 1.RGB转换为Tcolor

function RGBToColor(R,G,B: byte): Tcolor;
begin
  Result := B Shl 16 or G  shl 8 or R;
end;
 

// 2.Tcolor转换为RGB
 
proceudre Tform1.Button1Clink(Sender: Tobject);
var
  Color: TColor;
  R, G, B: integer;
begin
  Color := ClBlack;
  R := Color and $FF;
  G := (Color and $FF00) shr 8;
  B := (Color and $FF0000) shr 16;
end;

 

4、

5、

 

转载于:https://www.cnblogs.com/CodeSkill/p/5834079.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值