Esempio n. 1
0
        private static Bitmap extractItem(Bitmap list)
        {
            Bitmap item = null;

            try {
                if (list != null && list.Width > 0 && list.Height > 0)
                {
                    int      x   = 32 + 9;
                    Bitmap   bmp = new Bitmap(list.Width - x, 32);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.DrawImage(list, 0 - x, 0, list.Width, list.Height);
                    g.Dispose();
                    item = OCRTools.divideItem(bmp);
                }
            }
            catch (Exception e) { item = null; }
            return(item);
        }
Esempio n. 2
0
 private static object[] getCurrentSearch()
 {
     object[] currentItems = null;
     Bitmap[] item         = OCRTools.getCurrentItem();
     if (item != null && item.Length == 2)
     {
         OCRTools.saveBitmap(item[0], "capture_photo", true);
         OCRTools.saveBitmap(item[1], "capture_name", true);
         string name = OCRDecoder.getTextBitmap("capture_name");
         OCRTools.deleteBitmap("capture_name", true);
         if (name != null && name.Length > 0)
         {
             currentItems    = new object[2];
             currentItems[0] = item[0];
             currentItems[1] = name;
         }
     }
     return(currentItems);
 }
Esempio n. 3
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);
        }
Esempio 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);
                }
            }
        }