delphi 颜色选取


本文整理自网络,侵删。

 本例效果图:


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
procedure FormCreate(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

const
TargetColor: TColor = clRed;
var
SeedColor: TColor;
x1,y1: Integer;
pic: TPicture;

procedure TForm1.FormCreate(Sender: TObject);
begin
Image1.AutoSize := True;
Image1.Picture.LoadFromFile('c:\temp\test.bmp');
x1 := Image1.Left;
y1 := Image1.Top;
pic := Image1.Picture;
Button1.Caption := '恢复';
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
w,h: Integer;
ImgHdc: HDC;
begin
ImgHdc := Image1.Canvas.Handle;
SeedColor := GetPixel(ImgHdc, X,Y);

for w := 0 to Image1.Width-1 do
for h := 0 to Image1.Height-1 do
if GetPixel(ImgHdc, w,h)=SeedColor then
SetPixelV(Canvas.Handle, x1+w, y1+h, TargetColor);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Picture := pic;
end;

end.

相关阅读 >>

Delphi isipadress 非正则表达式验证ip的方法

Delphi string.parse

Delphi fmx下怎么得到当前程序的路径和文件名称?

Delphi 使用onvalidate事件或onvalidating事件验证在输入字段(tedit)中输入的值

Delphi 链接获取主站地址

Delphi idsmtp控件发送邮件

Delphi cb_addstring 与lb_addstring的区别?

Delphi 强迫将半型英数字转换成全型英数字

两种方法用Delphi实现域名转ip地址---用nmhttp控件和winsock

Delphi删除只读文件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...