var
buf1, buf2: TBuf;
procedure
LoagIMG(
var
buffer: TBuf; img: TImage; Name:
String
);
var
x,y,c:
integer
;
p: pByteArray;
begin
img
.
Picture
.
LoadFromFile(Name);
img
.
Picture
.
Bitmap
.
PixelFormat:=pf24bit;
x:=
0
; y:=
0
; x:=
0
;
SetLength(buffer, img
.
Height, img
.
Width);
for
y:=
0
to
img
.
Height-
1
do
begin
p:=img
.
Picture
.
Bitmap
.
ScanLine[y];
for
x:=
0
to
img
.
Width-
1
do
begin
c:=((p[x*
3
+
0
]
shl
8
+p[x*
3
+
1
])
shl
8
)+p[x*
3
+
2
];
buffer[y,x]:=c;
end
;
end
;
end
;
function
TForm1
.
CompareIMG: FRes;
var
y, x, yy, xx:
integer
;
begin
y:=
0
;
repeat
x:=
0
;
repeat
Result
.
found:=
true
;
yy:=
0
;
repeat
xx:=
0
;
repeat
if
buf1[y+yy, x+xx]<>buf2[yy,xx]
then
Result
.
found:=
false
;
inc(xx);
until
(xx>=Image2
.
Width)
or
(
Not
Result
.
found);
inc(yy);
until
(yy>=Image2
.
Height)
or
(
Not
Result
.
found);
inc(x);
until
(x>Image1
.
Width-Image2
.
Width)
or
(Result
.
found);
inc(y);
until
(y>Image1
.
Height-Image2
.
Height)
or
(Result
.
found);
if
Result
.
found
then
begin
Result
.
x:=x-
1
;
Result
.
y:=y-
1
;
end
;
end
;
type
FRes =
record
found:
boolean
;
x,y:
integer
;
end
;
var
FindResult: FRes;
begin
LoagIMG(buf1,Image1 ,
'C:\Bot\Screen.bmp'
);
LoagIMG(buf2, Image2,
'C:\Bot\AB.bmp'
);
FindResult:=CompareIMG;
if
FindResult
.
found
then
ShowMessage(
'Нашел'
);
end
;