相关资料:

http://blog.csdn.net/tokimemo/article/details/18702689

http://www.myexception.cn/delphi/215402.html

http://bbs.csdn.net/topics/390627275

结果总结:

1.生成的环中间会少一部分颜色,颜色会小于16581375。

2.手动选择颜色不准,手容易抖,要支持用户输入准确的数值。

代码实例:

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7. Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
  8.  
  9. type
  10. TForm1 = class(TForm)
  11. Button1: TButton;
  12. Image1: TImage;
  13. CheckBox1: TCheckBox;
  14. Label1: TLabel;
  15. Label2: TLabel;
  16. Label3: TLabel;
  17. Label4: TLabel;
  18. Label5: TLabel;
  19. Label6: TLabel;
  20. procedure Button1Click(Sender: TObject);
  21. procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  22. Y: Integer);
  23. private
  24. { Private declarations }
  25. public
  26. { Public declarations }
  27. end;
  28.  
  29. var
  30. Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.dfm}
  35.  
  36. //生成RGB色环的代码绘制
  37. //传入图片的大小
  38. function CreateColorCircle(const size: integer): TBitmap;
  39. var
  40. i,j,x,y: Integer;
  41. radius: integer;
  42. perimeter,arc,degree,step: double;
  43. R,G,B: byte;
  44. color: TColor;
  45. begin
  46. radius := round(size / );
  47. RESULT := TBitmap.Create;
  48. R:=;
  49. G:=;
  50. B:=;
  51. with RESULT do
  52. begin
  53. width := size;
  54. height:= size;
  55. pixelFormat := pf24bit;
  56. Canvas.Brush.Color := RGB(R,G,B);
  57. x := size + ;
  58. y := round(radius) + ;
  59. Canvas.FillRect(Rect(size,round(radius),x,y));
  60. for j := to size do
  61. begin
  62. perimeter := (size - j) * PI + ;
  63. arc := perimeter / ;
  64. step := ( * ) / perimeter ; //颜色渐变步长
  65. for i := to round(perimeter) - do
  66. begin
  67. degree := / perimeter * i;
  68. x := round(cos(degree * PI / ) * (size - j + ) / ) + radius;//数学公式,最后加上的是圆心点
  69. y := round(sin(degree * PI / ) * (size - j + ) / ) + radius;
  70.  
  71. if (degree > ) and (degree <= ) then
  72. begin
  73. R := ;
  74. G := ;
  75. B := round(step * i);
  76. end;
  77. if (degree > ) and (degree <= ) then
  78. begin
  79. if perimeter / / * (degree - ) > 1.0 then
  80. R := - round(step * (i - arc))
  81. else
  82. R := - round(step * ABS(i - arc));
  83. G := ;
  84. B := ;
  85. end;
  86. if (degree > ) and (degree <= ) then
  87. begin
  88. R := ;
  89. if perimeter / / * (degree - ) > 1.0 then
  90. G := round(step * (i - * arc))
  91. else
  92. G := round(step * ABS(i - * arc));
  93. B := ;
  94. end;
  95. if (degree > ) and (degree <= ) then
  96. begin
  97. R := ;
  98. G := ;
  99. if perimeter / / * (degree - ) > 1.0 then
  100. B := - round(step * (i - perimeter / ))
  101. else
  102. B := - round(step * ABS(i - perimeter / ));
  103. end;
  104. if (degree > ) and (degree <= ) then
  105. begin
  106. if perimeter / / * (degree - ) > 1.0 then
  107. R := round(step * (i - * arc))
  108. else
  109. R := round(step * ABS(i - * arc)) ;
  110. G := ;
  111. B := ;
  112. end;
  113. if (degree > ) and (degree <= ) then
  114. begin
  115. R := ;
  116. if perimeter / / * (degree - ) > 1.0 then
  117. G := - round(step * (i - * arc))
  118. else
  119. G := - round(step * ABS(i - * arc));
  120. B := ;
  121. end;
  122. color := RGB( ROUND(R + ( - R)/size * j),ROUND(G + ( - G) / size * j),ROUND(B + ( - B) / size * j));
  123. Canvas.Brush.Color := color;
  124. //为了绘制出来的圆好看,分成四个部分进行绘制
  125. if (degree >= ) and (degree <= ) then
  126. Canvas.FillRect(Rect(x,y,x-,y-));
  127. if (degree > ) and (degree <= ) then
  128. Canvas.FillRect(Rect(x,y,x-,y-));
  129. if (degree > ) and (degree <= ) then
  130. Canvas.FillRect(Rect(x,y,x+,y+));
  131. if (degree > ) and (degree <= ) then
  132. Canvas.FillRect(Rect(x,y,x+,y+));
  133. if (degree > ) and (degree <= ) then
  134. Canvas.FillRect(Rect(x,y,x-,y-));
  135. end;
  136. end;
  137. end;
  138. end;
  139.  
  140. //扣出中心的黑色圆
  141. //输入图片与中心圆的半径
  142. procedure BuckleHole(ABitmap: TBitmap; ARadius: Integer);
  143. var
  144. oBmp :TBitmap;
  145. oRgn :HRGN;
  146. begin
  147. // oBmp := TBitmap.Create; //为了代码整齐就不写try了
  148. // oBmp.PixelFormat := ABitmap.PixelFormat;
  149. // oBmp.Width := ABitmap.Width;
  150. // oBmp.Height := ABitmap.Height;
  151. // BitBlt(oBmp.Canvas.Handle, 0, 0, oBmp.Width, oBmp.Height, ABitmap.Canvas.Handle, 80, 80, SRCCOPY); //要拷贝的位图
  152. // oRgn := CreateEllipticRgn(0, 0, 100, 100); //创建圆形区域
  153. // SelectClipRgn(ABitmap.Canvas.Handle, oRgn); //选择剪切区域
  154. // ABitmap.Canvas.Draw(0, 0, oBmp); //位图位于区域内的部分加载
  155. // oBmp.Free;
  156. // DeleteObject(oRgn);
  157. ABitmap.Canvas.Pen.Color := clBlack;
  158. ABitmap.Canvas.Brush.Style := bsClear;
  159. ABitmap.Canvas.Brush.Color := clBlack;
  160. ABitmap.Canvas.Ellipse(Trunc(ABitmap.Width/)-ARadius, Trunc(ABitmap.Height/)-ARadius,
  161. Trunc(ABitmap.Width/)+ARadius, Trunc(ABitmap.Height/)+ARadius);
  162. end;
  163.  
  164. //把中心圆做成透明的
  165. procedure MyDraw(ABitmap: TBitmap; ARadius: Integer);
  166. var
  167. bf: BLENDFUNCTION;
  168. desBmp, srcBmp: TBitmap;
  169. rgn: HRGN;
  170. begin
  171. with bf do
  172. begin
  173. BlendOp := AC_SRC_OVER;
  174. BlendFlags := ;
  175. AlphaFormat := ;
  176. SourceConstantAlpha := ; // 透明度,0~255
  177. end;
  178.  
  179. desBmp := TBitmap.Create;
  180. srcBmp := TBitmap.Create;
  181.  
  182. try
  183. srcBmp.Assign(ABitmap);
  184.  
  185. desBmp.Width := srcBmp.Width;
  186. desBmp.Height := srcBmp.Height;
  187.  
  188. Winapi.Windows.AlphaBlend(desBmp.Canvas.Handle, , ,
  189. desBmp.Width, desBmp.Height, srcBmp.Canvas.Handle,
  190. , , srcBmp.Width, srcBmp.Height, bf);
  191.  
  192. rgn := CreateEllipticRgn(Trunc(ABitmap.Width/)-ARadius, Trunc(ABitmap.Height/)-ARadius,
  193. Trunc(ABitmap.Width/)+ARadius, Trunc(ABitmap.Height/)+ARadius); // 创建一个圆形区域
  194. SelectClipRgn(srcBmp.Canvas.Handle, rgn);
  195. srcBmp.Canvas.Draw(, , desBmp);
  196.  
  197. ABitmap.Assign(nil);
  198. ABitmap.Assign(srcBmp);
  199. finally
  200. desBmp.Free;
  201. srcBmp.Free;
  202. end
  203. end;
  204.  
  205. procedure TForm1.Button1Click(Sender: TObject);
  206. var
  207. oBitmap: TBitmap;
  208. rgn: HRGN;
  209. begin
  210. oBitmap := CreateColorCircle(Image1.Width);
  211. if CheckBox1.Checked then //要不要代中心圆选项
  212. // BuckleHole(oBitmap, 100);
  213. MyDraw(oBitmap, );
  214. Image1.Picture.Graphic := oBitmap;
  215. oBitmap.Free;
  216. end;
  217.  
  218. procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  219. Y: Integer);
  220. var
  221. oColor: TColor;
  222. begin
  223. //鼠标移动时提取颜色RGB的值
  224. with Image1 do
  225. oColor := GetPixel(GetDC(Parent.Handle), X + left,Y + Top);
  226. Label4.Caption := IntToStr(oColor and $FF);
  227. Label5.Caption := IntToStr((oColor and $FF00) shr );
  228. Label6.Caption := IntToStr((oColor and $FF0000) shr );
  229. end;
  230.  
  231. end.

Delphi实现RGB色环的代码绘制(XE10.2+WIN764)的更多相关文章

  1. Delphi汉字简繁体转换代码(分为D7和D2010版本)

    //delphi 7 Delphi汉字简繁体转换代码unit ChineseCharactersConvert; interface uses   Classes, Windows; type   T ...

  2. delphi 常用属性+方法+事件+代码+函数

    内容居中(属性) alignment->tacenter mome控件 禁用最大化(属性) 窗体-> BorderIcons属性-> biMaximize-> False 让鼠 ...

  3. Delphi图像处理 -- RGB与HSV转换

    阅读提示:     <Delphi图像处理>系列以效率为侧重点,一般代码为PASCAL,核心代码采用BASM.     <C++图像处理>系列以代码清晰,可读性为主,全部使用C ...

  4. Delphi图像处理 -- RGB与HSL转换

    阅读提示:     <Delphi图像处理>系列以效率为侧重点,一般代码为PASCAL,核心代码采用BASM.     <C++图像处理>系列以代码清晰,可读性为主,全部使用C ...

  5. Delphi语言最好的JSON代码库 mORMot学习笔记1

    mORMot没有控件安装,直接添加到lib路径,工程中直接添加syncommons,syndb等到uses里 --------------------------------------------- ...

  6. delphi 微信(WeChat)多开源代码

    在网上看到一个C++代码示例: 原文地址:http://bbs.pediy.com/thread-217610.htm 觉得这是一个很好的调用 windows api 的示例,故将其转换成了 delp ...

  7. Delphi如何在Form的标题栏绘制自定义文字

    Delphi中Form窗体的标题被设计成绘制在系统菜单的旁边,如果你想要在标题栏绘制自定义文本又不想改变Caption属性,你需要处理特定的Windows消息:WM_NCPAINT.. WM_NCPA ...

  8. Delphi调用JAVA的WebService上传XML文件(XE10.2+WIN764)

    相关资料:1.http://blog.csdn.net/luojianfeng/article/details/512198902.http://blog.csdn.net/avsuper/artic ...

  9. Delphi语言最好的JSON代码库 mORMot学习笔记1(无数评论)

    mORMot没有控件安装,直接添加到lib路径,工程中直接添加syncommons,syndb等到uses里 --------------------------------------------- ...

随机推荐

  1. 算法中的 log 到底是什么?

    之前一直不解为何算法中经常会看到 log 今天看<数据结构与算法分析 Java 语言描述>(第 3 版)2.4.3 节 求最大子序列和的分治算法实现时才注意到原因 翻看第 29 页的最后一 ...

  2. Docker 构建Hadoop环境

    参考如下文章: Docker安装Hadoop Docker在本地搭建Hadoop分布式集群 Docker快速搭建Hadoop测试环境 从0开始用docker搭建 hadoop分布式环境 Docker- ...

  3. 带你开发一款给Apk中自己主动注入代码工具icodetools(开凿篇)

    一.前言 从这篇開始咋们開始一个全新的静态方式逆向工具icodetools的实现过程.这个也是我自己第一次写的个人认为比較实用的小工具,特别是在静态方式逆向apk找关键点的时候.兴许会分为三篇来具体介 ...

  4. jquery获取radio值

    单选组radio: $("input[@type=radio][@checked]").val(); 单选组 radio: $("input[@type=radio]&q ...

  5. 【转载】linux 测试机器端口连通性方法

    转载原文:http://blog.csdn.net/z1134145881/article/details/54706711 下面一一介绍: 1 telnet方法 2 wget方法 3 ssh方法 4 ...

  6. Sublime text —— 自定义主题Soda

    编辑器的主题有两种,一种是语法高亮颜色主题,一种是编辑器自身显示主题,如果要自定义编辑器样式,个人推荐soda. Ctrl+Shift+p 输入install,接着输入  soda,选择  Theme ...

  7. VS Code 中文注释显示乱码 解决方法

    将设置中的"files.autoGuessEncoding"项的值改为true即可. 1.文件 2.首选项 3.设置 4.搜索 "files.autoGuessEncod ...

  8. ganglia安装 by frank

    作者是frank. 1.安装epelrpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm2. ...

  9. Spring Security教程(四):自定义登录页

    在前面的例子中,登陆页面都是用的Spring Security自己提供的,这明显不符合实际开发场景,同时也没有退出和注销按钮,因此在每次测试的时候都要通过关闭浏览器来注销达到清除session的效果. ...

  10. category使用 objc_setAssociatedObject/objc_getAssociatedObject 实现添加属性

    属性 其实就是get/set 方法.我们可以使用  objc_setAssociatedObject/objc_getAssociatedObject  实现 动态向类中添加 方法 @interfac ...