Exemplo n.º 1
0
        public static int FindFirstPixelDist(Bitmap oBitmap, ScanSideBegin uScanSide, Color backGrundColor)
        {
            bool bColorFound = false;
            int  i           = 0;

            switch (uScanSide)
            {
                #region RIGHT

            case ScanSideBegin.RIGHT:    // ------------ Search First Pixel RIGHT
                for (i = (oBitmap.Width - 1); i > 0; i--)
                {
                    for (int i2 = 1; i2 < oBitmap.Height; i2++)
                    {
                        if (oBitmap.GetPixel(i, i2) != backGrundColor)
                        {
                            bColorFound = true;
                            break;
                        }
                    }
                    if (bColorFound)
                    {
                        break;
                    }
                }
                break;

                #endregion

                #region LEFT

            case ScanSideBegin.LEFT: // ------------ Search First Pixel LEFT

                for (i = 1; i < oBitmap.Width; i++)
                {
                    for (int i2 = 1; i2 < oBitmap.Height; i2++)
                    {
                        if (oBitmap.GetPixel(i, i2) != backGrundColor)
                        {
                            bColorFound = true;
                            break;
                        }
                    }
                    if (bColorFound)
                    {
                        break;
                    }
                }
                //UpperLeft.X = i - 1;
                break;

                #endregion

                #region DOWN

            case ScanSideBegin.BOTTOM: // ------------ Search First Pixel Down
                for (i = (oBitmap.Height - 1); i > 0; i--)
                {
                    for (int i2 = 1; i2 < oBitmap.Width; i2++)
                    {
                        if (oBitmap.GetPixel(i2, i) != backGrundColor)
                        {
                            bColorFound = true;
                            break;
                        }
                    }
                    if (bColorFound)
                    {
                        break;
                    }
                }
                //DownRight.Y = i;
                break;

                #endregion

                #region UP

            case ScanSideBegin.TOP: // ------------ Search First Pixel UP
                for (i = 1; i < oBitmap.Height; i++)
                {
                    for (int i2 = 1; i2 < oBitmap.Width; i2++)
                    {
                        if (oBitmap.GetPixel(i2, i) != backGrundColor)
                        {
                            bColorFound = true;
                            break;
                        }
                    }
                    if (bColorFound)
                    {
                        break;
                    }
                }
                //UpperLeft.Y = i - 1;
                break;

                #endregion
            }

            return(i);
        }
Exemplo n.º 2
0
        public static int FindFirstPixelDist(Bitmap oBitmap, ScanSideBegin uScanSide, Color backGrundColor) {
            bool bColorFound = false;
            int i = 0;

            switch (uScanSide) {

            #region RIGHT

            case ScanSideBegin.RIGHT:    // ------------ Search First Pixel RIGHT 
                for (i = (oBitmap.Width - 1); i > 0; i--) {

                    for (int i2 = 1; i2 < oBitmap.Height; i2++) {
                        if (oBitmap.GetPixel(i, i2) != backGrundColor) {
                            bColorFound = true;
                            break;
                        }
                    }
                    if (bColorFound) { break; }
                }
            break;

            #endregion

            #region LEFT

            case ScanSideBegin.LEFT: // ------------ Search First Pixel LEFT
            
                for (i = 1; i < oBitmap.Width; i++) {

                    for (int i2 = 1; i2 < oBitmap.Height; i2++) {
                        if (oBitmap.GetPixel(i, i2) != backGrundColor) {
                            bColorFound = true;
                            break;
                        }
                    }
                    if (bColorFound) { break; }
                }
                //UpperLeft.X = i - 1;
            break;

            #endregion

            #region DOWN

            case ScanSideBegin.BOTTOM: // ------------ Search First Pixel Down
                for (i = (oBitmap.Height - 1); i > 0; i--) {

                    for (int i2 = 1; i2 < oBitmap.Width; i2++) {
                        if (oBitmap.GetPixel(i2, i) != backGrundColor) {
                            bColorFound = true;
                            break;
                        }
                    }
                    if (bColorFound) { break; }
                }
                //DownRight.Y = i;
            break;

            #endregion

            #region UP

            case ScanSideBegin.TOP: // ------------ Search First Pixel UP
                for (i = 1; i < oBitmap.Height; i++) {
                    for (int i2 = 1; i2 < oBitmap.Width; i2++) {
                        if (oBitmap.GetPixel(i2, i) != backGrundColor) {
                            bColorFound = true;
                            break;
                        }
                    }
                    if (bColorFound) { break; }
                }
                //UpperLeft.Y = i - 1;
            break;

            #endregion

            }

            return i;
        }