Delphi color finding and Color Block

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.