Exemplo n.º 1
0
        private async void btn_Select(object sender, RoutedEventArgs e)
        {
            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    break;
                }
                if (loadFrom.ItemType == typeof(GetText))
                {
                    gettext = loadFrom;
                }
                loadFrom = loadFrom.Parent;
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    match = await getrectangle.GetitAsync();

                    tip.Close();
                    tip = null;
                }
            }
            else
            {
                var Image       = loadFrom.GetValue <string>("Image");
                var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
                var b           = new System.Drawing.Bitmap(stream);
                var Threshold   = loadFrom.GetValue <double>("Threshold");
                var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                var Processname = loadFrom.GetValue <string>("Processname");
                var limit       = loadFrom.GetValue <Rectangle>("Limit");
                if (Threshold < 0.5)
                {
                    Threshold = 0.8;
                }

                Interfaces.GenericTools.minimize(Interfaces.GenericTools.mainWindow);
                System.Threading.Thread.Sleep(100);
                var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                if (matches.Count() == 0)
                {
                    Interfaces.GenericTools.restore();
                    return;
                }
                match = matches[0];
            }

            Rectangle rect = Rectangle.Empty;

            using (Interfaces.Overlay.OverlayWindow _overlayWindow = new Interfaces.Overlay.OverlayWindow(true))
            {
                _overlayWindow.BackColor = System.Drawing.Color.Blue;
                _overlayWindow.Visible   = true;
                _overlayWindow.Bounds    = match;
                _overlayWindow.TopMost   = true;

                var tip = new Interfaces.Overlay.TooltipWindow("Select relative area to capture");
                rect = await getrectangle.GetitAsync();

                tip.Close();
                tip = null;
            }

            ModelItem.Properties["OffsetX"].SetValue(new System.Activities.InArgument <int>(rect.X - match.X));
            ModelItem.Properties["OffsetY"].SetValue(new System.Activities.InArgument <int>(rect.Y - match.Y));
            ModelItem.Properties["Width"].SetValue(new System.Activities.InArgument <int>(rect.Width));
            ModelItem.Properties["Height"].SetValue(new System.Activities.InArgument <int>(rect.Height));
            Interfaces.GenericTools.restore();
        }
        private async Task <Rectangle> GetBaseRectangle()
        {
            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            var pp = ModelItem.Properties["Element"];

            if (pp.IsSet)
            {
                while (loadFrom.Parent != null)
                {
                    var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                    if (p != null)
                    {
                        loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                        break;
                    }
                    if (loadFrom.ItemType == typeof(GetText))
                    {
                        gettext = loadFrom;
                    }
                    loadFrom = loadFrom.Parent;
                }
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
                match = element.Rectangle;
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    match = await getrectangle.GetitAsync();

                    tip.Close();
                    tip = null;
                }
            }
            else if (match.IsEmpty)
            {
                var image = loadFrom.GetValue <string>("Image");
                if (!string.IsNullOrEmpty(image))
                {
                    Bitmap b = Task.Run(() => {
                        return(Interfaces.Image.Util.LoadBitmap(image));
                    }).Result;
                    using (b)
                    {
                        var Threshold   = loadFrom.GetValue <double>("Threshold");
                        var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                        var Processname = loadFrom.GetValue <string>("Processname");
                        var limit       = loadFrom.GetValue <Rectangle>("Limit");
                        if (Threshold < 0.5)
                        {
                            Threshold = 0.8;
                        }

                        Interfaces.GenericTools.Minimize(Interfaces.GenericTools.MainWindow);
                        System.Threading.Thread.Sleep(100);
                        var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                        if (matches.Count() == 0)
                        {
                            Interfaces.GenericTools.Restore();
                            return(Rectangle.Empty);
                        }
                        match = matches[0];
                    }
                }
            }

            return(match);
        }
Exemplo n.º 3
0
        private void Highlight_Click(object sender, RoutedEventArgs e)
        {
            var OffsetX = ModelItem.GetValue <int>("OffsetX");
            var OffsetY = ModelItem.GetValue <int>("OffsetY");
            var Width   = ModelItem.GetValue <int>("Width");
            var Height  = ModelItem.GetValue <int>("Height");

            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    break;
                }
                if (loadFrom.ItemType == typeof(GetText))
                {
                    gettext = loadFrom;
                }
                loadFrom = loadFrom.Parent;
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    return;
                    //var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    //match = await getrectangle.GetitAsync();
                    //tip.Close();
                    //tip = null;
                }
            }
            else
            {
                var Image       = loadFrom.GetValue <string>("Image");
                var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
                var b           = new System.Drawing.Bitmap(stream);
                var Threshold   = loadFrom.GetValue <double>("Threshold");
                var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                var Processname = loadFrom.GetValue <string>("Processname");
                var limit       = loadFrom.GetValue <Rectangle>("Limit");
                if (Threshold < 0.5)
                {
                    Threshold = 0.8;
                }

                // Interfaces.GenericTools.minimize(Interfaces.GenericTools.mainWindow);
                System.Threading.Thread.Sleep(100);
                var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                if (matches.Count() == 0)
                {
                    Interfaces.GenericTools.restore();
                    return;
                }
                match = matches[0];
            }

            var _hi = new ImageElement(match);

            _hi.Highlight(false, System.Drawing.Color.Blue, TimeSpan.FromSeconds(1));

            var rect = new ImageElement(new Rectangle(_hi.X + OffsetX, _hi.Y + OffsetY, Width, Height));

            rect.Highlight(false, System.Drawing.Color.PaleGreen, TimeSpan.FromSeconds(1));
        }