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字符串隐藏一法

Delphi 窗体内控件实现滚动字母

Delphi 通�^窗口句柄或窗口标题得到进程句柄

Delphi操作ini配置文件

Delphi 如何将颜色值转换为html格式?

强大的Delphi rtti--兼谈需要了解多种开发语言

Delphi xe 移动平台 showmodal 范例

Delphi中使用goo.gl(google的缩短url服务)api

Delphi 任务栏显示进度条 createcomobject(clsid_taskbarlist) as itaskbarlist4

Delphi stringgrid 加载excel表格文件内容自动宽度

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



打赏

取消

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

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

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

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

评论

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