unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 =
class
(TForm)
img1: TImage;
img2: TImage;
btn_load1: TBitBtn;
btn_load2: TBitBtn;
btn_compare: TBitBtn;
dlgOpen1: TOpenDialog;
procedure
btn_load1Click(Sender: TObject);
procedure
FormCreate(Sender: TObject);
procedure
btn_load2Click(Sender: TObject);
procedure
btn_compareClick(Sender: TObject);
private
public
end
;
var
Form1: TForm1;
implementation
{
$R
*.dfm}
procedure
TForm1
.
btn_load1Click(Sender: TObject);
begin
if
dlgOpen1
.
Execute
then
if
(FileExists(dlgOpen1
.
FileName))
then
img1
.
Picture
.
LoadFromFile(dlgOpen1
.
FileName);
end
;
procedure
TForm1
.
FormCreate(Sender: TObject);
begin
img1
.
AutoSize :=
True
;
img1
.
Center :=
True
;
img2
.
AutoSize :=
True
;
img2
.
Center :=
True
;
end
;
procedure
TForm1
.
btn_load2Click(Sender: TObject);
begin
if
dlgOpen1
.
Execute
then
if
(FileExists(dlgOpen1
.
FileName))
then
img2
.
Picture
.
LoadFromFile(dlgOpen1
.
FileName);
end
;
procedure
TForm1
.
btn_compareClick(Sender: TObject);
var
ms1, ms2: TMemoryStream;
size:
Int64
;
begin
ms1 := TMemoryStream
.
Create;
ms2 := TMemoryStream
.
Create;
try
try
img1
.
Picture
.
Bitmap
.
SaveToStream(ms1);
img2
.
Picture
.
Bitmap
.
SaveToStream(ms2);
except
ms1
.
Free;
ms2
.
Free;
end
;
if
ms1
.
Size <> ms2
.
Size
then
begin
ShowMessage(
'不一致'
);
end
else
begin
if
ms1
.
Size > ms2
.
Size
then
size := ms1
.
Size
else
size := ms2
.
Size;
if
CompareMem(ms1
.
Memory, ms2
.
Memory, size)
then
ShowMessage(
'一致'
)
else
ShowMessage(
'不一致'
);
end
;
finally
ms1
.
Free;
ms2
.
Free;
end
;
end
;
end
.
上一页 [1] [2]