public void Update()
        {
            wowScreen.GetPosition(out var p);
            rectangle.X = p.X;
            rectangle.Y = p.Y;
            capturer.Capture(rectangle);

            for (int i = 0; i < frames.Length; i++)
            {
                FrameColor[frames[i].index] = capturer.GetColorAt(frames[i].point);
            }
        }
        public void Execute()
        {
            npcNameFinder.ChangeNpcType(NpcNames.Enemy | NpcNames.Neutral);

            capturer.Capture();

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();
            this.npcNameFinder.Update();
            stopwatch.Stop();
            logger.LogInformation($"Update: {stopwatch.ElapsedMilliseconds}ms");

            var bitmap = capturer.GetBitmap(capturer.Rect.Width, capturer.Rect.Height);

            using (var gr = Graphics.FromImage(bitmap))
            {
                Font       drawFont  = new Font("Arial", 10);
                SolidBrush drawBrush = new SolidBrush(Color.White);

                if (npcNameFinder.Npcs.Count > 0)
                {
                    using (var whitePen = new Pen(Color.White, 1))
                    {
                        gr.DrawRectangle(whitePen, npcNameFinder.Area);

                        npcNameFinder.Npcs.ForEach(n =>
                        {
                            npcNameTargeting.locTargetingAndClickNpc.ForEach(l =>
                            {
                                gr.DrawEllipse(whitePen, l.X + n.ClickPoint.X, l.Y + n.ClickPoint.Y, 5, 5);
                            });
                        });


                        npcNameFinder.Npcs.ForEach(n => gr.DrawRectangle(whitePen, new Rectangle(n.Min, new Size(n.Width, n.Height))));
                        npcNameFinder.Npcs.ForEach(n => gr.DrawString(npcNameFinder.Npcs.IndexOf(n).ToString(), drawFont, drawBrush, new PointF(n.Min.X - 20f, n.Min.Y)));
                    }
                }
            }

            npcNameFinder.Npcs.ForEach(n =>
            {
                logger.LogInformation($"{npcNameFinder.Npcs.IndexOf(n),2} -> rect={new Rectangle(n.Min.X, n.Min.Y, n.Width, n.Height)} ClickPoint={{{n.ClickPoint.X,4},{n.ClickPoint.Y,4}}}");
            });

            logger.LogInformation("\n");

            bitmap.Save("target_names.png");
        }
Exemplo n.º 3
0
 public void UpdateScreenshot()
 {
     GetRectangle(out var rect);
     capturer.Capture(rect);
 }
        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            capturer.Capture();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            this.npcNameFinder.Update();
            stopwatch.Stop();
            //logger.LogInformation($"Update: {stopwatch.ElapsedMilliseconds}ms");

            var bitmap = new Bitmap(capturer.Rect.Width, capturer.Rect.Height);

            using (var gr = Graphics.FromImage(bitmap))
            {
                Font       drawFont  = new Font("Arial", 10);
                SolidBrush drawBrush = new SolidBrush(Color.White);

                if (npcNameFinder.Npcs.Count > 0)
                {
                    using (var whitePen = new Pen(Color.White, 1))
                    {
                        gr.DrawRectangle(whitePen, npcNameFinder.Area);

                        npcNameFinder.Npcs.ForEach(n =>
                        {
                            //npcNameTargeting.locTargetingAndClickNpc.ForEach(l =>
                            //{
                            //gr.DrawEllipse(whitePen, l.X + n.ClickPoint.X, l.Y + n.ClickPoint.Y, 5, 5);
                            gr.DrawEllipse(whitePen, n.ClickPoint.X, n.ClickPoint.Y, 5, 5);
                            //});
                        });


                        npcNameFinder.Npcs.ForEach(n => gr.DrawRectangle(whitePen, new Rectangle(n.Min, new System.Drawing.Size(n.Width, n.Height))));
                        npcNameFinder.Npcs.ForEach(n => gr.DrawString(npcNameFinder.Npcs.IndexOf(n).ToString(), drawFont, drawBrush, new PointF(n.Min.X - 20f, n.Min.Y)));
                    }
                }
            }

            npcNameFinder.Npcs.ForEach(n =>
            {
                //logger.LogInformation($"{npcNameFinder.Npcs.IndexOf(n),2} -> rect={new Rectangle(n.Min.X, n.Min.Y, n.Width, n.Height)} ClickPoint={{{n.ClickPoint.X,4},{n.ClickPoint.Y,4}}}");
            });

            //logger.LogInformation("\n");

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                if (capturer != null)
                {
                    this.Screenshot.Source = ToBitmapImage(capturer.DirectBitmap.Bitmap);
                }

                this.Screenshot2.Source = ToBitmapImage(bitmap);
                Duration.Content        = "Duration: " + stopwatch.ElapsedMilliseconds + "ms";

                bitmap.Dispose();
                bitmap = null;
            }));
        }