toGrayscale() public static method

public static toGrayscale ( Bitmap original ) : Bitmap
original System.Drawing.Bitmap
return System.Drawing.Bitmap
Example #1
0
        private static Bitmap divideItem(Bitmap list)
        {
            Bitmap bmp = null;

            try
            {
                if (list != null && list.Width > 0 && list.Height > 0)
                {
                    list = OCRTools.cleanImage(list);
                    bmp  = new Bitmap(list.Width, 32 / 2);

                    Graphics g = Graphics.FromImage(bmp);
                    g.DrawImage(list, 0, 0, list.Width, list.Height);
                    g.Dispose();

                    bmp = OCRTools.toGrayscale(bmp);
                    saveBitmap(bmp, "name", false);
                    bmp = resizeImage(bmp, new Size(bmp.Width * 4, bmp.Height * 4));
                }
            }
            catch (Exception e) { bmp = null; }
            return(bmp);
        }
Example #2
0
        public void initDetectZones()
        {
            Wim32API.Rect rectTabPanel = new Wim32API.Rect();
            Wim32API.GetWindowRect(hwndChild, ref rectTabPanel);
            Rectangle rectangleTabPanel = new Rectangle();

            rectangleTabPanel.X      = rectTabPanel.Left;
            rectangleTabPanel.Y      = rectTabPanel.Top;
            rectangleTabPanel.Width  = rectTabPanel.Right - rectTabPanel.Left + 1;
            rectangleTabPanel.Height = rectTabPanel.Bottom - rectTabPanel.Top + 1;

            Wim32API.SetForegroundWindow(hwnd);

            Bitmap bmpInitial = OCRTools.getBitmap(hwndChild);

            bmpInitial = OCRTools.toGrayscale(bmpInitial);

            List <Bitmap> bmpList = new List <Bitmap>();

            bmpList.Add(bmpInitial);

            int Y = rectangleTabPanel.Y + (rectangleTabPanel.Height / 2);
            int X = rectangleTabPanel.X + rectangleTabPanel.Width;

            while (true)
            {
                Wim32API.SetCursorPos(X, Y);
                X -= 10;
                Bitmap bmp = OCRTools.getBitmap(hwndChild);
                bmp = OCRTools.toGrayscale(bmp);
                if (bmp != null && bmp != bmpInitial && !isBlackImage(bmp) && !containsArray(bmpList, bmp))
                {
                    bmpList.Add(bmp);
                }
                if (X < rectangleTabPanel.X)
                {
                    break;
                }
                Thread.Sleep(100);
            }

            Bitmap[] capturedBitmaps = null;
            if (bmpList.Count > 0)
            {
                capturedBitmaps = bmpList.ToArray();
                bmpList.Clear();
            }

            if (capturedBitmaps != null && capturedBitmaps.Length > 0)
            {
                Rectangle[] zonesBar = detectBarZones(capturedBitmaps);
                Array.Sort(zonesBar, delegate(Rectangle rect1, Rectangle rect2) {
                    int rsp = 0;
                    if (rect1.X < rect2.X)
                    {
                        rsp = -1;
                    }
                    else if (rect1.X > rect2.X)
                    {
                        rsp = 1;
                    }
                    return(rsp);
                });
                capturedBitmaps = null;
                if (detectedHandler != null && zonesBar != null && zonesBar.Length > 0)
                {
                    detectedHandler.Invoke(rectangleTabPanel, zonesBar);
                }
            }
        }