Exemplo n.º 1
0
 public static Bitmap getBitmap(IntPtr handle)
 {
     Bitmap bmp = null;
     try {
         Wim32API.Rect rect = new Wim32API.Rect();
         Wim32API.GetWindowRect(handle, ref rect);
         bmp = new Bitmap(rect.Right - rect.Left, rect.Bottom - rect.Top);
         Graphics memoryGraphics = Graphics.FromImage(bmp);
         IntPtr dc = memoryGraphics.GetHdc();
         bool success = Wim32API.PrintWindow(handle, dc, 0);
         memoryGraphics.ReleaseHdc(dc);
     }
     catch (Exception e) { bmp = null; }
     return bmp;
 }
Exemplo n.º 2
0
        public static Bitmap getBitmap(IntPtr handle)
        {
            Bitmap bmp = null;

            try {
                Wim32API.Rect rect = new Wim32API.Rect();
                Wim32API.GetWindowRect(handle, ref rect);
                bmp = new Bitmap(rect.Right - rect.Left, rect.Bottom - rect.Top);
                Graphics memoryGraphics = Graphics.FromImage(bmp);
                IntPtr   dc             = memoryGraphics.GetHdc();
                bool     success        = Wim32API.PrintWindow(handle, dc, 0);
                memoryGraphics.ReleaseHdc(dc);
            }
            catch (Exception e) { bmp = null; }
            return(bmp);
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
                }
            }
        }