Ejemplo n.º 1
0
        /// <summary>Locate and image in the screen and return the coordinates (X, Y, Width, height) of the image</summary>
        /// <param name="path">Path of the image to look for</param>
        /// <param name="attempts">Amount of tries to look for the image in the screen</param>
        /// <param name="region">Region of the screen to look for the image, for more details look for ScreenRegions class</param>
        /// <param name="waitInterval">Amount of time in milliseconds to wait for each attempts before starting to look for the image again</param>
        public static Rect Find(string path, int attempts = 0, Rect region = null, int waitInterval = 1000)
        {
            ValidateImage(path);
            for (int i = 0; i <= attempts; i++)
            {
                using (ImagePattern pattern = new ImagePattern(new Bitmap(Bitmap.FromFile(path))))
                {
                    Rectangle currentRegion = region == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(region);

                    Area area = new Area(currentRegion);

                    Quellatalo.Nin.TheEyes.Match match = area.Find(pattern);
                    if (match == null)
                    {
                        Thread.Sleep(waitInterval);
                        continue;
                    }
                    else
                    {
                        return(region == null?RectangleToRect(match.Rectangle) : FixCoordinates(currentRegion, match.Rectangle));
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        ///<summary>Performs an screenShot of the entire screen</summary>
        /// <param name="fullPath">path to save the capture image</param>
        public static bool Capture(string fullPath)
        {
            string folderPath = Path.GetDirectoryName(fullPath);
            string filename   = Path.GetFileName(fullPath);

            if (!Directory.Exists(folderPath))
            {
                throw new Exception(string.Format("The Directory {0} is not valid", folderPath));
            }
            if (!ValidExtensions.Contains(Path.GetExtension(filename).ToLower()))
            {
                throw new Exception(string.Format("The file extension is not valid, consider use png or jpg"));
            }

            Rectangle rect = Image.RectToRectangle(ScreenRegions.Complete());
            Bitmap    bmp  = new Bitmap(rect.Size.Width, rect.Size.Height);

            //string fullPath = Path.Combine(folderPath,filename);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.CopyFromScreen(0, 0, 0, 0, rect.Size);
                bmp.Save(fullPath);
            }
            return(File.Exists(fullPath));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// HightLight a given region with the specified color
        /// </summary>
        /// <param name="rectToHightLight">The region to hightLight</param>
        /// <param name="hightLightColor">The color to use to fill the region</param>
        private static void HighLight(Rect rectToHightLight, Color hightLightColor)
        {
            Rectangle currentRegion = rectToHightLight == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(rectToHightLight);

            Area area = new Area(currentRegion);

            area.Highlight(new SolidBrush(hightLightColor));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// HightLight a given region with the specified pen
        /// </summary>
        /// <param name="rectToHightLight">The region to hightLight</param>
        /// <param name="pen">The pen to use to hightLight the given region</param>
        public static void HighLight(Rect rectToHightLight, Pen pen)
        {
            Rectangle currentRegion = rectToHightLight == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(rectToHightLight);

            Area area = new Area(currentRegion);

            area.Highlight(pen);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// HightLight a given region with the specified color and opacity
        /// </summary>
        /// <param name="rectToHightLight">The region to hightLight</param>
        /// <param name="hightLightColor">The color to use to fill the region</param>
        /// <param name="opacity">The opacity of the color</param>
        public static void HighLight(Rect rectToHightLight, Color hightLightColor, int opacity)
        {
            Rectangle currentRegion = rectToHightLight == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(rectToHightLight);

            Area area = new Area(currentRegion);

            area.Highlight(new SolidBrush(Color.FromArgb(opacity, hightLightColor)));
        }
Ejemplo n.º 6
0
        /// <summary>Locate all ocurrences of and image in the screen</summary>
        /// <param name="image">image to look for</param>
        /// <param name="region">Region of the screen to look for the image, for more details look for ScreenRegions class</param>
        public static IEnumerable <Rect> FindAll(Bitmap image, Rect region = null)
        {
            ICollection <Rect> results = new List <Rect>();

            using (ImagePattern pattern = new ImagePattern(image))
            {
                Rectangle currentRegion = region == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(region);

                Area area = new Area(currentRegion);
                IEnumerable <Quellatalo.Nin.TheEyes.Match> matches = area.FindAll(pattern);
                foreach (Quellatalo.Nin.TheEyes.Match match in matches)
                {
                    results.Add(region == null ? RectangleToRect(match.Rectangle) : FixCoordinates(currentRegion, match.Rectangle));
                }
                return(results);
            }
        }
Ejemplo n.º 7
0
        /// <summary>Locate and image in the screen and return true if the image is found</summary>
        /// <param name="image">image to look for</param>
        /// <param name="attempts">Amount of tries to look for the image in the screen</param>
        /// <param name="region">Region of the screen to look for the image, for more details look for ScreenRegions class</param>
        /// <param name="waitInterval">Amount of time in milliseconds to wait for each attempts before starting to look for the image again</param>
        public static bool Exist(Bitmap image, int attempts = 0, Rect region = null, int waitInterval = 1000)
        {
            for (int i = 0; i <= attempts; i++)
            {
                using (ImagePattern pattern = new ImagePattern(new Bitmap(image)))
                {
                    Rectangle currentRegion = region == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(region);

                    Area area = new Area(currentRegion);

                    Quellatalo.Nin.TheEyes.Match match = area.Find(pattern);
                    if (match == null)
                    {
                        Thread.Sleep(waitInterval);
                        continue;
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }