示例#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;
                    }
                }
            }
示例#2
0
            public override Rectangle FindNext()
            {
                Rectangle rectangle;

                _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);
                    rectangle        = base.FindNext();
                }
                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);
                    }
                }
                return(rectangle);
            }
            public virtual Rectangle FindNext()
            {
                Rectangle empty;

                _searchOnData  = null;
                _searchForData = null;
                try
                {
                    _searchOnData  = BitmapHelper.LockBits(_searchOn, ImageLockMode.ReadOnly);
                    _searchForData = BitmapHelper.LockBits(_searchFor, ImageLockMode.ReadOnly);
                    if (_searchFinished)
                    {
                        return(Rectangle.Empty);
                    }
                    if (!_searchStarted)
                    {
                        throw new ApplicationException(
                                  "Search is not started. Use StartSearch prior to calling FindNext");
                    }
                    if (_offset != 0)
                    {
                        goto Label_02CE;
                    }
                    _offset++;
                    if (!CheckLocation(_x, _y))
                    {
                        goto Label_02CE;
                    }
                    return((Rectangle)_result[_result.Count - 1]);

Label_00A3:
                    switch (_pos)
                    {
                    case 0:
                        _x0 = _x - _i + 1;
                        _y0 = _y - _offset;
                        break;

                    case 1:
                        _x0 = _x + _i;
                        _y0 = _y - _offset;
                        break;

                    case 2:
                        _x0 = _x + _offset;
                        _y0 = _y - _i + 1;
                        break;

                    case 3:
                        _x0 = _x + _offset;
                        _y0 = _y + _i;
                        break;

                    case 4:
                        _x0 = _x + _i - 1;
                        _y0 = _y + _offset;
                        break;

                    case 5:
                        _x0 = _x - _i;
                        _y0 = _y + _offset;
                        break;

                    case 6:
                        _x0 = _x - _offset;
                        _y0 = _y + _i - 1;
                        break;

                    case 7:
                        _x0 = _x - _offset;
                        _y0 = _y - _i;
                        break;
                    }
                    _pos++;
                    if (CheckLocation(_x0, _y0))
                    {
                        if (_result.Count <= _maxCount)
                        {
                            return((Rectangle)_result[_result.Count - 1]);
                        }
                        return(Rectangle.Empty);
                    }
Label_028A:
                    if (_pos < 8)
                    {
                        goto Label_00A3;
                    }
                    _i++;
                    _pos = 0;
Label_02AB:
                    if (_i <= _offset)
                    {
                        goto Label_028A;
                    }
                    _offset++;
                    _i = 1;
Label_02CE:
                    if (_offset <= _maxOffset)
                    {
                        goto Label_02AB;
                    }
                    _searchFinished = true;
                    empty           = Rectangle.Empty;
                }
                finally
                {
                    if (_searchForData != null)
                    {
                        BitmapHelper.UnlockBits(_searchFor, _searchForData);
                    }
                    if (_searchOnData != null)
                    {
                        BitmapHelper.UnlockBits(_searchOn, _searchOnData);
                    }
                }
                return(empty);
            }