Color finding and color blocks are an important basis for simulation.
Sometimes, you need to determine whether a color appears at a certain point, and sometimes you need to determine whether the color block appears at a certain position.
Sometimes, you need to check whether there is a color block in the range.
Function iscolor (BMP: tbitmap; X, Y: integer; C: tcolor): Boolean;
VaR
Row: prgbtriparray;
P: trgbtriple;
Begin
Row: = BMP. scanline [y];
P: = row [x];
Result: = (P. rgbtblue = getbvalue (c) and (P. rgbtgreen = getgvalue (c ))
And (P. rgbtred = getrvalue (c ));
End;
Function iscolorblock (BMP: tbitmap; x, y, N: integer; C: tcolor): Boolean;
VaR
I, J: integer;
Begin
Result: = false;
For J: = y to Y + n-1 do
Begin
For I: = x to X + n-1 do
Begin
If not iscolor (BMP, I, j, c) Then // if the color is incorrect, it is not a color block.
Exit;
End;
End;
Result: = true; // This is the color block.
End;
Function findcolorblock (BMP: tbitmap; X1, Y1, X2, Y2, N: integer; C: tcolor): tpoint;
VaR
I, J: integer;
Begin
For J: = Y1 to Y2 do
Begin
For I: = x1 to X2 do
Begin
If iscolor (BMP, I, j, c) Then // first find the color point
Begin
If iscolorblock (BMP, I, j, 3, C) Then // determine the color block
Begin
Result. X: = I;
Result. Y: = J;
Exit; // find and return
End;
End;
End;
End;
Result. X: =-1;
Result. Y: =-1;
End;