以下代码可实现你的要求:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
BitBtn1: TBitBtn;
Timer1: TTimer;
Image3: TImage;
procedure BitBtn1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
cl:boolean;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Timer1.Enabled:=not Timer1.Enabled;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i : INTEGER;
j : INTEGER;
bw: Tcolor;
begin
cl:=not cl;
if cl then bw:= clblack else bw:=clwhite;
for i:=0 to Image1.Width-1 do
for j:=0 to Image1.Height-1 do
begin
if Image1.Canvas.Pixels[i,j]<>Image2.Canvas.Pixels[i,j] then
Image3.Canvas.Pixels[i,j]:=bw else
Image3.Canvas.Pixels[i,j]:=Image1.Canvas.Pixels[i,j];
end;
end;
end.