Jump to content
alin2012

find color in tpointarray

Recommended Posts

Yes, it is, but not using just 1 function. There's several ways you can actually do this. You could use [wiki=GetColors]GetColors[/wiki] to get the colors at all of these coordinates and manually search them. You could build a [wiki=TPointArray]TPointArray[/wiki] with all points you do not want to search and use [wiki=FindColorSkipCoords]FindColorSkipCoords[/wiki]. I would however advice to use [wiki=FindColorsTolerance]FindColorsTolerance[/wiki] to find all of the colors you are looking for in a search area and then filter out the points that you wanted to look for.

 

function FindColorToleranceCoords(var x, y: Integer; const Color: Integer;
 const Points: TPointArray; const Tolerance: Integer): Boolean;
var
 b: TBox;
 p: TPointArray;
 i, j, k, l: Integer;
begin
 Result := False;
 b := GetTPABounds(Points);
 if not FindColorsTolerance(p, Color, b.x1, b.y1, b.x2, b.y2, Tolerance) then Exit;
 l := Length(p);
 k := Length(Points);
 for i := 0 to k - 1 do
   for j := 0 to l - 1 do
     if (p[j].X = Points[i].X) and (p[j].Y = Points[i].Y) then
     begin
       x := Points[i].X;
       y := Points[i].Y;
       Result := True;
       Exit;
     end;
end;

var
 TPA: TPointArray;
 x, y: Integer;

begin
 TPA := [Point(273, 60), Point(475, 63)];
 if FindColorToleranceCoords(x, y, 0, TPA, 1) then
   WriteLn(IntToStr(x) + ',' + IntToStr(y));
end.

 

SCAR Divi 3.26 will contain TPA functions to make this a lot faster and do it far more efficiently, but since it's still in beta I wrote the code for SCAR Divi 3.25

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...