示例#1
0
            public void StartSearch(Bitmap topLeft, Bitmap topRight, Bitmap bottomLeft, Bitmap bottomRight,
                                    Rectangle searchArea, Point startFrom, int maxCount, int tolerance)
            {
                int[] numArray;
                _topLeft     = BitmapHelper.CloneBitmap(topLeft);
                _topRight    = BitmapHelper.CloneBitmap(topRight);
                _bottomLeft  = BitmapHelper.CloneBitmap(bottomLeft);
                _bottomRight = BitmapHelper.CloneBitmap(bottomRight);
                base.StartSearch(topLeft, searchArea, startFrom, maxCount, tolerance);
                _topLeftData     = null;
                _topRightData    = null;
                _bottomLeftData  = null;
                _bottomRightData = null;
                try
                {
                    _topLeftData     = BitmapHelper.LockBits(_topLeft, ImageLockMode.ReadOnly);
                    _topRightData    = BitmapHelper.LockBits(_topRight, ImageLockMode.ReadOnly);
                    _bottomLeftData  = BitmapHelper.LockBits(_bottomLeft, ImageLockMode.ReadOnly);
                    _bottomRightData = BitmapHelper.LockBits(_bottomRight, ImageLockMode.ReadOnly);
                    numArray         = new[]
                    {
                        CornerQuality(_topLeftData), CornerQuality(_topRightData), CornerQuality(_bottomLeftData),
                        CornerQuality(_bottomRightData)
                    };
                }
                finally
                {
                    if (_topLeftData != null)
                    {
                        BitmapHelper.UnlockBits(_topLeft, _topLeftData);
                    }
                    if (_topRightData != null)
                    {
                        BitmapHelper.UnlockBits(_topRight, _topRightData);
                    }
                    if (_bottomLeftData != null)
                    {
                        BitmapHelper.UnlockBits(_bottomLeft, _bottomLeftData);
                    }
                    if (_bottomRightData != null)
                    {
                        BitmapHelper.UnlockBits(_bottomRight, _bottomRightData);
                    }
                }
                var num = -2147483648;

                _startCorner = -1;
                for (var i = 0; i < numArray.Length; i++)
                {
                    if (numArray[i] > num)
                    {
                        num          = numArray[i];
                        _startCorner = i;
                    }
                }
            }
            public Rectangle[] FindAll(Bitmap searchFor, Rectangle searchArea, Point startFrom, int maxCount,
                                       int borderWidth, int tolerance)
            {
                _borderWidth = borderWidth;
                if (_borderWidth < 1)
                {
                    _borderWidth = 1;
                }
                var image = BitmapHelper.CloneBitmap(searchFor);
                var rect  = new Rectangle(borderWidth, borderWidth, image.Width - 2 * borderWidth,
                                          image.Height - 2 * borderWidth);

                BitmapHelper.MaskRectangle(image, rect, true);
                return(base.FindAll(image, searchArea, startFrom, maxCount, tolerance));
            }
            public virtual void StartSearch(Bitmap searchFor, Rectangle searchArea, Point startFrom, int maxCount,
                                            int tolerance)
            {
                BitmapHelper.CheckBitmap(searchFor);
                _searchFor      = BitmapHelper.CloneBitmap(searchFor);
                _startFrom      = startFrom;
                _tolerance      = tolerance * 0xfe01 / 100;
                _searchStarted  = true;
                _maxCount       = maxCount;
                _searchFinished = false;
                var rectangle = searchArea;

                rectangle.Intersect(new Rectangle(0, 0, _searchOn.Width, _searchOn.Height));
                rectangle.Width  -= _searchFor.Width - 1;
                rectangle.Height -= _searchFor.Height - 1;
                _sl           = rectangle.Left;
                _st           = rectangle.Top;
                _sr           = rectangle.Right;
                _sb           = rectangle.Bottom;
                _startFrom.X -= _searchFor.Width / 2;
                _startFrom.Y -= _searchFor.Height / 2;
                if (_startFrom.X < _sl)
                {
                    _startFrom.X = _sl;
                }
                if (_startFrom.Y < _st)
                {
                    _startFrom.Y = _st;
                }
                if (_startFrom.X >= _sr)
                {
                    _startFrom.X = _sr - 1;
                }
                if (_startFrom.Y >= _sb)
                {
                    _startFrom.Y = _sb - 1;
                }
                _maxOffset = Math.Max(Math.Max(_startFrom.X - _sl, _sr - _startFrom.X),
                                      Math.Max(_startFrom.Y - _st, _sb - _startFrom.Y));
                _x      = _startFrom.X;
                _y      = _startFrom.Y;
                _offset = 0;
                _i      = 1;
                _pos    = 0;
                _result = new ArrayList(_maxCount);
            }
 public BitmapSearch(Bitmap searchOn)
 {
     _searchOn = BitmapHelper.CloneBitmap(searchOn);
 }