урок на делфи 33 - Сравнение рисунков


задание на delphi. сравнить два бмп рисунка


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)
Image1: TImage;
Image2: TImage;
Button1: TButton;
Image3: TImage;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
bmp1,bmp2,bmp3:TBitmap;
x,y:integer;
a1,a2:Integer;
chet:integer;
begin
bmp1:=TBitmap.Create;
bmp1.Width := Image1.Picture.Bitmap.Width;
bmp1.Height:= Image1.Picture.Bitmap.Height;
bmp2:=TBitmap.Create;
bmp2.Width := Image1.Picture.Bitmap.Width;
bmp2.Height:= Image1.Picture.Bitmap.Height;
bmp3:=TBitmap.Create;
bmp3.Width := Image1.Picture.Bitmap.Width;
bmp3.Height:= Image1.Picture.Bitmap.Height;
chet:=0;
bmp1.Assign(Image1.Picture.Bitmap);
bmp2.Assign(Image2.Picture.Bitmap);
for y := 0 to bmp1.Height - 1 do
begin
for x := 0 to bmp1.Width - 1 do
begin
a1:=bmp1.Canvas.Pixels[x,y];
a2:=bmp2.Canvas.Pixels[x,y];
if a1=a2 then
begin
chet:=chet+1;
bmp3.Canvas.Pixels[x,y]:=a1;
end;
end;
end;
Label1.Caption:='Совпадений '+IntToStr(chet);
Image3.Picture.Assign(bmp3);
bmp3.SaveToFile('3.bmp');
FreeAndNil(bmp1);
FreeAndNil(bmp2);
FreeAndNil(bmp3);
end;
end.



Скачать