相关资料:

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

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

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

结果总结:

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

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

代码实例:

 unit Unit1;

 interface

 uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
CheckBox1: TCheckBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} //生成RGB色环的代码绘制
//传入图片的大小
function CreateColorCircle(const size: integer): TBitmap;
var
i,j,x,y: Integer;
radius: integer;
perimeter,arc,degree,step: double;
R,G,B: byte;
color: TColor;
begin
radius := round(size / );
RESULT := TBitmap.Create;
R:=;
G:=;
B:=;
with RESULT do
begin
width := size;
height:= size;
pixelFormat := pf24bit;
Canvas.Brush.Color := RGB(R,G,B);
x := size + ;
y := round(radius) + ;
Canvas.FillRect(Rect(size,round(radius),x,y));
for j := to size do
begin
perimeter := (size - j) * PI + ;
arc := perimeter / ;
step := ( * ) / perimeter ; //颜色渐变步长
for i := to round(perimeter) - do
begin
degree := / perimeter * i;
x := round(cos(degree * PI / ) * (size - j + ) / ) + radius;//数学公式,最后加上的是圆心点
y := round(sin(degree * PI / ) * (size - j + ) / ) + radius; if (degree > ) and (degree <= ) then
begin
R := ;
G := ;
B := round(step * i);
end;
if (degree > ) and (degree <= ) then
begin
if perimeter / / * (degree - ) > 1.0 then
R := - round(step * (i - arc))
else
R := - round(step * ABS(i - arc));
G := ;
B := ;
end;
if (degree > ) and (degree <= ) then
begin
R := ;
if perimeter / / * (degree - ) > 1.0 then
G := round(step * (i - * arc))
else
G := round(step * ABS(i - * arc));
B := ;
end;
if (degree > ) and (degree <= ) then
begin
R := ;
G := ;
if perimeter / / * (degree - ) > 1.0 then
B := - round(step * (i - perimeter / ))
else
B := - round(step * ABS(i - perimeter / ));
end;
if (degree > ) and (degree <= ) then
begin
if perimeter / / * (degree - ) > 1.0 then
R := round(step * (i - * arc))
else
R := round(step * ABS(i - * arc)) ;
G := ;
B := ;
end;
if (degree > ) and (degree <= ) then
begin
R := ;
if perimeter / / * (degree - ) > 1.0 then
G := - round(step * (i - * arc))
else
G := - round(step * ABS(i - * arc));
B := ;
end;
color := RGB( ROUND(R + ( - R)/size * j),ROUND(G + ( - G) / size * j),ROUND(B + ( - B) / size * j));
Canvas.Brush.Color := color;
//为了绘制出来的圆好看,分成四个部分进行绘制
if (degree >= ) and (degree <= ) then
Canvas.FillRect(Rect(x,y,x-,y-));
if (degree > ) and (degree <= ) then
Canvas.FillRect(Rect(x,y,x-,y-));
if (degree > ) and (degree <= ) then
Canvas.FillRect(Rect(x,y,x+,y+));
if (degree > ) and (degree <= ) then
Canvas.FillRect(Rect(x,y,x+,y+));
if (degree > ) and (degree <= ) then
Canvas.FillRect(Rect(x,y,x-,y-));
end;
end;
end;
end; //扣出中心的黑色圆
//输入图片与中心圆的半径
procedure BuckleHole(ABitmap: TBitmap; ARadius: Integer);
var
oBmp :TBitmap;
oRgn :HRGN;
begin
// oBmp := TBitmap.Create; //为了代码整齐就不写try了
// oBmp.PixelFormat := ABitmap.PixelFormat;
// oBmp.Width := ABitmap.Width;
// oBmp.Height := ABitmap.Height;
// BitBlt(oBmp.Canvas.Handle, 0, 0, oBmp.Width, oBmp.Height, ABitmap.Canvas.Handle, 80, 80, SRCCOPY); //要拷贝的位图
// oRgn := CreateEllipticRgn(0, 0, 100, 100); //创建圆形区域
// SelectClipRgn(ABitmap.Canvas.Handle, oRgn); //选择剪切区域
// ABitmap.Canvas.Draw(0, 0, oBmp); //位图位于区域内的部分加载
// oBmp.Free;
// DeleteObject(oRgn);
ABitmap.Canvas.Pen.Color := clBlack;
ABitmap.Canvas.Brush.Style := bsClear;
ABitmap.Canvas.Brush.Color := clBlack;
ABitmap.Canvas.Ellipse(Trunc(ABitmap.Width/)-ARadius, Trunc(ABitmap.Height/)-ARadius,
Trunc(ABitmap.Width/)+ARadius, Trunc(ABitmap.Height/)+ARadius);
end; //把中心圆做成透明的
procedure MyDraw(ABitmap: TBitmap; ARadius: Integer);
var
bf: BLENDFUNCTION;
desBmp, srcBmp: TBitmap;
rgn: HRGN;
begin
with bf do
begin
BlendOp := AC_SRC_OVER;
BlendFlags := ;
AlphaFormat := ;
SourceConstantAlpha := ; // 透明度,0~255
end; desBmp := TBitmap.Create;
srcBmp := TBitmap.Create; try
srcBmp.Assign(ABitmap); desBmp.Width := srcBmp.Width;
desBmp.Height := srcBmp.Height; Winapi.Windows.AlphaBlend(desBmp.Canvas.Handle, , ,
desBmp.Width, desBmp.Height, srcBmp.Canvas.Handle,
, , srcBmp.Width, srcBmp.Height, bf); rgn := CreateEllipticRgn(Trunc(ABitmap.Width/)-ARadius, Trunc(ABitmap.Height/)-ARadius,
Trunc(ABitmap.Width/)+ARadius, Trunc(ABitmap.Height/)+ARadius); // 创建一个圆形区域
SelectClipRgn(srcBmp.Canvas.Handle, rgn);
srcBmp.Canvas.Draw(, , desBmp); ABitmap.Assign(nil);
ABitmap.Assign(srcBmp);
finally
desBmp.Free;
srcBmp.Free;
end
end; procedure TForm1.Button1Click(Sender: TObject);
var
oBitmap: TBitmap;
rgn: HRGN;
begin
oBitmap := CreateColorCircle(Image1.Width);
if CheckBox1.Checked then //要不要代中心圆选项
// BuckleHole(oBitmap, 100);
MyDraw(oBitmap, );
Image1.Picture.Graphic := oBitmap;
oBitmap.Free;
end; procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
oColor: TColor;
begin
//鼠标移动时提取颜色RGB的值
with Image1 do
oColor := GetPixel(GetDC(Parent.Handle), X + left,Y + Top);
Label4.Caption := IntToStr(oColor and $FF);
Label5.Caption := IntToStr((oColor and $FF00) shr );
Label6.Caption := IntToStr((oColor and $FF0000) shr );
end; 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. 【ASP.NET】@Model类型的使用详解

    有时需要在ASP.NET MVC4的视图的@model中使用多个类型的实例,.NET Framework 4.0版本引入的System.Tuple类可以轻松满足这个需求. 假设Person和Produ ...

  2. 【Oracle】Oracle 的过程化SQL(PLSQL)中NULL值的处理

    下面是NULL的几个注意点: 1.NULL值既不是空格也不是0. 2.给表插入值的时候,如果没有给列指定列值,则默认为NULL. 3.当算术表达式里包含NULL值时,其计算结果也是NULL值. 这时候 ...

  3. android蓝牙开发---与蓝牙模块进行通信

    近半个月来一直在搞android蓝牙这方面,主要是项目需要与蓝牙模块进行通信.开头的进展很顺利,但因为蓝牙模块不在我这里,所以只能用手机测试.一开头就发现手机的蓝牙不能用,为了证明这点,我刷了四次不同 ...

  4. UI--仿IOS控件之ActionSheet样式 and more..

    ## <代码里的世界> -UI篇 用文字札记描绘自己 android学习之路 转载请保留出处 by Qiao http://blog.csdn.net/qiaoidea/article/d ...

  5. logrotate日志管理工具

    一.概述 logrotate是一个Linux系统默认安装了的日志文件管理工具,用来把旧文件轮转.压缩.删除,并且创建新的日志文件.我们可以根据日志文件的大小.天数等来转储,便于对日志文件管理. log ...

  6. Exception的妙用

    实际工作中遇到的一个例子: 一.看这样一个方法: /** 传入以微秒(us)为单位的时间字符串,转换成可读的(年-月-日 时:分:秒)日期格式*/ public String getDateStrin ...

  7. 如何修改电脑的本地网卡(非笔记本无限网卡)的mac地址

    计算机---设备管理器--找到对应的本地网卡---右键属性-----高级----网络地址

  8. shell 数组,双层循环打印变量

    双层循环,打印循环执行次数. 特别注意 ,shell 脚本赋值时 '=' 两侧不能有空格,否则报错,shell command not found 但在if 语句中需要有: STR1="ab ...

  9. python md5 问题(TypeError: Unicode-objects must be encoded before hashing)

    import hashlib import sys def md5s(): m=hashlib.md5() strs=sys.argv[1] m.update(strs.encode("ut ...

  10. tomcat 8.0 进程没有全部杀死

    The web application [FileIO_new_interface] created a ThreadLocal with key of type [java.lang.ThreadL ...