Esempio n. 1
0
 public void StartReading()
 {
     imgR = new ImageRead();
     imgR.onImageReaded += ImageReaded;
     imgR.ReadFullImage(TargetImage, JumpH, JumpV, ColorDiff, NoWhite);
 }
Esempio n. 2
0
        private static void DrawThread()
        {
            int currentX = Properties.Settings.Default.CanvasStart.X;
            int currentY = Properties.Settings.Default.CanvasStart.Y;

            Debug.WriteLine("Drawing image...");
            currentRGB = new int[3];
            //start selecting pen
            Cursor.Position = Properties.Settings.Default.PenLocation;
            MouseInput.simulator.Mouse.LeftButtonClick();
            Thread.Sleep(TSleep);

            bool holding = false;

            foreach (string color in image.Keys)
            {
                //read colors and change it
                if (!IsRunning)
                {
                    break;
                }
                if (holding)
                {
                    MouseInput.simulator.Mouse.LeftButtonUp(); holding = false;
                }
                if (ImageRead.GetStringFromRGB(currentRGB) != color)
                {
                    ChangeCurrentColor(ImageRead.GetRGBFromString(color));
                }

                List <int[]> positions = new List <int[]>();
                positions = image[color];

                for (int i = 0; i < positions.Count; i++)
                {
                    while (IsPaused)
                    {
                        if (!IsRunning)
                        {
                            break;
                        }
                    }
                    //get all coordinates for current color
                    int[] position = positions[i];

                    if (!IsRunning)
                    {
                        break;
                    }
                    //hold mouse cursor to draw a line
                    if (!holding)
                    {
                        Cursor.Position = new Point(currentX + position[0], currentY + position[1]); MouseInput.simulator.Mouse.LeftButtonDown(); holding = true;
                    }
                    try
                    {
                        int[] next = positions[i + 1];
                        int   xD   = Math.Abs(position[0] - next[0]);
                        int   yD   = Math.Abs(position[1] - next[1]);
                        if (xD > 0 || yD > MJump)
                        {
                            //set cursor to final position for current X, release mouse button and goto next
                            Cursor.Position = new Point(currentX + position[0], currentY + position[1]);
                            Thread.Sleep(TSleep);
                            MouseInput.simulator.Mouse.LeftButtonUp();
                            holding = false;
                            Thread.Sleep(TimeSpan.FromMilliseconds(TSleep));
                        }
                    } catch { break; }
                }
            }

            //raise event
            string result = IsRunning ? "Sucess" : "Stopped by user";

            Debug.WriteLine("Draw ended\nResult: " + result);

            if (holding)
            {
                MouseInput.simulator.Mouse.LeftButtonUp();
            }
            onDrawEnd(IsRunning);
            IsRunning = false;
        }