I am currently taking screenshots of the area in a loop to then search for 4 pixels in it. These pixels have the same color - red or $ 001300FF. The variables used are defined and initialized in the OnCreate event:
//The variables for the area:
ScanL := 500; // Left
ScanR := 800; // Right
ScanT := 180; // Top
ScanB := 400; // Bottom
screenshot: TBitMap;
canvas : TCanvas;
To take screenshots, I use the following function:
procedure TFormMain.GetSCREENSHOT(var a: TBitMap);
var
Locked: Boolean;
begin
Locked := Canvas.TryLock;
try
screenshot.Canvas.CopyRect(screenshot.Canvas.ClipRect, Canvas, Rect(ScanL, ScanT, ScanR, ScanB));
finally
if Locked then
Canvas.Unlock;
end;
end;
The variable "screenshot: TBitMap", globally defined, is passed to the GetSCREENSHOT function. To find these 4 pixels, I just did what a newbie would do:
function TFormMain.findImage : Boolean;
var
x,y : Integer;
begin
Result := false;
for x := 0 to screenshot.Width-10 do
begin
for y := 0 to screenshot.Height-10 do
begin
if screenshot.Canvas.Pixels[x,y] = $001300FF then
begin
if screenshot.Canvas.Pixels[x,y+1] = $001300FF then
if screenshot.Canvas.Pixels[x,y+2] = $001300FF then
if screenshot.Canvas.Pixels[x,y+3] = $001300FF then
begin
FoundPixelX := ScanL + x;
FoundPixelY := ScanT + Y;
Result := True;
Exit;
end;
end;
end;
end;
end;
Since it was so bad, I measured how long it took to run the function:
QueryPerformanceFrequency(freq);
QueryPerformanceCounter(startTime);
findImage;
QueryPerformanceCounter(endTime);
ShowMessage('the function needs about ' + IntToStr((endTime - startTime) * 1000 div freq) + 'ms');
108 ! . , , , , ! , .Pixels?!
: getSCREENSHOT 1 .