Example #1
0
        public void GetWindow(string imageName)
        {
            _graphicFactory.LoadImage(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"..\..\ImageTest\{imageName}"));
            var engine = new RegonizeEngine(_screenHelper);

            var r = new Rectangle {
                X = 700, Y = 45, Width = 500, Height = 600
            };
            var color = Color.FromArgb(20, 20, 20);
            var seuil = 20;

            var tmp = _screenHelper.ScreenArea(r);

            Clipboard.SetImage(ConvertBitmap(tmp));

            var filteredImage = RegonizeEngine.FilterImage(new Image <Bgr, byte>(tmp), new RegonizeEngine.FilterParam(color, seuil));

            Clipboard.SetImage(ConvertBitmap(filteredImage.Bitmap));

            var rr = engine.GetAllRectangles(tmp, r, color, seuil, new RegonizeEngine.ContourAcceptance
            {
                Height = 150, HeightOffset = 150, Width = 330, WidthOffset = 100, Size = 500, SizeOffset = 500
            });

            var zz = rr.OrderByDescending(a => a.Height + a.Width).Take(10).ToList();

            using (var g = Graphics.FromImage(tmp))
            {
                g.DrawRectangles(new Pen(Color.Red, 2), zz.ToArray());
            }

            Clipboard.SetImage(ConvertBitmap(tmp));
        }
Example #2
0
        public void MatchPatternTest(string imageName, string patternName)
        {
            var engine      = new RegonizeEngine(_screenHelper);
            var sourceImage = new Image <Bgr, byte>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"..\..\ImageTest\{imageName}"));
            var searchImg   = new Image <Bgr, byte>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"..\..\ImageTest\{patternName}"));

            var result = engine.MatchPattern(sourceImage, searchImg);

            sourceImage.Draw(result, new Bgr(Color.Red), 2);

            Clipboard.SetImage(ConvertBitmap(sourceImage.Bitmap));
        }
        /// <summary>
        /// Copies the screen image to clipboard.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="quality">The quality.</param>
        /// <param name="rectangle">The rectangle.</param>
        /// <param name="encoder">The encoder.</param>
        public static void CopyScreenImageToClipboard(UIElement source, double scale, int quality, Rectangle rectangle, BitmapEncoder encoder = null)
        {
            using (var stream = GetScreenImageStream(source, scale, quality, encoder ?? new PngBitmapEncoder()))
            {
                var img = (Bitmap)Image.FromStream(stream);

                if (!rectangle.IsEmpty)
                {
                    img = img.Clone(rectangle.Contract(1), img.PixelFormat);
                }

                var bmpSource = BitmapToBitmapSource(img);
                Clipboard.SetImage(bmpSource);
            }
        }
Example #4
0
        private void GetValue(RectEventArgs args, Rectangle r)
        {
            var b = _screenHelper.ScreenArea(r);

            var bmp = new Bitmap(Convert.ToInt32(args.Rect.Width), Convert.ToInt32(args.Rect.Height),
                                 PixelFormat.Format32bppArgb);

            using (var grD = Graphics.FromImage(bmp))
            {
                grD.DrawImage(b, new Rectangle(0, 0, Convert.ToInt32(args.Rect.Width), Convert.ToInt32(args.Rect.Height)),
                              new Rectangle(Convert.ToInt32(args.Rect.X), Convert.ToInt32(args.Rect.Y), Convert.ToInt32(args.Rect.Width),
                                            Convert.ToInt32(args.Rect.Height)), GraphicsUnit.Pixel);
            }

            Clipboard.SetImage(ConvertBitmap(bmp));
        }
Example #5
0
        public void SetData(TransferDataType type, Func <object> dataSource)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (dataSource == null)
            {
                throw new ArgumentNullException("dataSource");
            }

            if (type == TransferDataType.Image)
            {
                BitmapSource bmp = dataSource() as BitmapSource;
                if (bmp == null)
                {
                    throw new ArgumentException("data is not the incorrect type", "data");
                }

                WindowsClipboard.SetImage(bmp);
                return;
            }

            if (type == TransferDataType.Text)
            {
                string text = dataSource() as string;
                if (text == null)
                {
                    throw new ArgumentException("data is not the correct type", "data");
                }

                WindowsClipboard.SetText(text);
                return;
            }

            if (type == TransferDataType.Text)
            {
                string text = dataSource() as string;
                if (text == null)
                {
                    throw new ArgumentException("data is not the correct type", "data");
                }

                WindowsClipboard.SetText(text, TextDataFormat.Rtf);
                return;
            }
        }
Example #6
0
        //Parse byte[] to Image and write to Clipboard
        private void CopyClipboard(byte[] cimg)
        {
            //Parse byte[] to Images
            var image = new System.Windows.Media.Imaging.BitmapImage();

            using (var mem = new MemoryStream(cimg)) {
                mem.Position = 0;
                image.BeginInit();
                image.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.PreservePixelFormat;
                image.CacheOption   = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                image.UriSource     = null;
                image.StreamSource  = mem;
                image.EndInit();
            }
            image.Freeze();

            //Copy whole Image to Clipboard
            Clipboard.SetImage(image);
        }
Example #7
0
        //Parse byte[] to Image and write to Clipboard
        private static void CopyClipboard(byte[] cimg)
        {
            //Parse byte[] to Images
            BitmapImage image = new BitmapImage();

            using (MemoryStream mem = new MemoryStream(cimg)) {
                mem.Position = 0;
                image.BeginInit();
                image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                image.CacheOption   = BitmapCacheOption.OnLoad;
                image.UriSource     = null;
                image.StreamSource  = mem;
                image.EndInit();
            }
            image.Freeze();

            //Copy whole Image to Clipboard
            Clipboard.SetImage(image);
        }
        private void CopySelectedScreenshot()
        {
            if (_selectedScreenshot == null)
            {
                Log.Warn("Cannot copy screenshot, no screenshot selected");
                return;
            }

            using (var fs = new FileStream(_selectedScreenshot.Path, FileMode.Open, FileAccess.Read))
            {
                var img = new BitmapImage();

                img.BeginInit();
                img.StreamSource = fs;
                img.EndInit();

                Clipboard.SetImage(img);
            }
        }
Example #9
0
        public void GetTrianglesOfFishingGame(int xCoord, RegonizeEngine.FishTriangle.Orientation orientation)
        {
            //620-310
            //87-127
            var pointOfTimeGauge = new System.Drawing.Point(87 + 620, 127 + 310);

            _graphicFactory.LoadImage(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\ImageTest\b.jpg"));

            var r = new Rectangle {
                X = pointOfTimeGauge.X - 35, Y = pointOfTimeGauge.Y - 45, Width = 380, Height = 17
            };

            var filteredImage = RegonizeEngine.FilterImage(new Image <Bgr, byte>(_screenHelper.ScreenArea(r)),
                                                           new RegonizeEngine.FilterParam(Color.FromArgb(0, 85, 255), 100));

            var t = new RegonizeEngine.FishTriangle(filteredImage, new System.Drawing.Point(xCoord, 8));

            Clipboard.SetImage(ConvertBitmap(t.GetBitmap()));

            Assert.AreEqual(orientation, t.GetOrientation());
        }
Example #10
0
        public BitmapSource CopyToClipBoard()
        {
            RectangleGeometry clip = Image.Clip as RectangleGeometry;

            if (clip == null)
            {
                return(null);
            }

            var clipRect = clip.Rect;

            try
            {
                var width  = (int)Math.Min(Image.ActualWidth - clipRect.X, clipRect.Width);
                var height = (int)Math.Min(Image.ActualHeight - clipRect.Y, clipRect.Height);

                var rect = new Rect(new Size(width, height));


                CroppedBitmap cb = new CroppedBitmap(_screen, new Int32Rect((int)clipRect.X, (int)clipRect.Y, (int)width, (int)height));

                DrawingVisual  visual  = new DrawingVisual();
                DrawingContext context = visual.RenderOpen();
                context.DrawImage(cb, rect);
                context.DrawRectangle(new VisualBrush(AdornerRectangle), null, rect);
                context.Close();

                var dpi  = VisualTreeHelper.GetDpi(this);
                var dpix = Convert.ToSingle(dpi.PixelsPerInchX);
                RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, dpix, dpix, PixelFormats.Pbgra32);
                bmp.Render(visual);

                Clipboard.SetImage(bmp);
                return(bmp);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Example #11
0
        public void SetClipboardContent(string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                return;
            }

            if (content.StartsWith(pngImageHeader))
            {
                try {
                    byte[] rawImage = Convert.FromBase64String(content.Remove(0, pngImageHeader.Length));
                    using (MemoryStream imageStream = new MemoryStream(rawImage, 0, rawImage.Length)) {
                        BitmapImage bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.StreamSource = imageStream;
                        bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                        bitmap.EndInit();
                        bitmap.Freeze();
                        WinClipboard.SetImage(bitmap);
                    }
                }
                catch (Exception ex) {
                    Logger.Error("Error while trying to set clipboard image content!", ex);
                    return;
                }
            }
            else
            {
                try {
                    WinClipboard.SetDataObject(content, true);
                } catch (ExternalException ex) {
                    Logger.Error("Error while trying to set clipboard text content!", ex);
                    return;
                }
            }

            lastSetContent = content;
        }
Example #12
0
        private async void BtnNew_OnClick(object sender, RoutedEventArgs e)
        {
            if (!(IudDelay.Value is int delay))
            {
                return;
            }

            await Task.Delay(1000 *delay);

            var snip = new Snip {
                PreviewCommand = new RelayCommand(
                    param => PreviewSnip(param as Snip),
                    param => param is Snip
                    ),
                CopyCommand = new RelayCommand(
                    param => {
                    if (param is Snip pSnip)
                    {
                        Clipboard.SetImage(pSnip.BitmapImageScreenshot);
                    }
                },
                    param => param is Snip
                    )
            };

            snip.TakeScreenshot();

            Hide();
            var screenshotTaker = new ScreenshotTaker(snip)
            {
                Enqueue = _snips.Enqueue
            };

            screenshotTaker.ShowDialog();
            Show();
        }
Example #13
0
 void Copy()
 {
     Clipboard.SetImage(tabControlManager.CurrentTab.ImagePresenter.ImageArea.Source as BitmapSource);
 }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var cancelButton = Template.FindName("CancelButton", this) as ImageButton;
            var fileButton = Template.FindName("FileButton", this) as ImageButton;
            var folderButton = Template.FindName("FolderButton", this) as ImageButton;
            var detailsButton = Template.FindName("DetailsButton", this) as ImageButton;
            var copyMenu = Template.FindName("CopyMenuItem", this) as ImageMenuItem;
            var copyImageMenu = Template.FindName("CopyImageMenuItem", this) as ImageMenuItem;
            var copyFilenameMenu = Template.FindName("CopyFilenameMenuItem", this) as ImageMenuItem;
            var copyFolderMenu = Template.FindName("CopyFolderMenuItem", this) as ImageMenuItem;

            if (cancelButton != null)
                cancelButton.Click += (s, a) => RaiseCancelClickedEvent();

            //Open file.
            if (fileButton != null)
                fileButton.Click += (s, a) =>
                {
                    RaiseOpenFileClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && File.Exists(OutputFilename))
                            Process.Start(OutputFilename);
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Open File", "Error while openning the file", ex.Message);
                    }
                };

            //Open folder.
            if (folderButton != null)
                folderButton.Click += (s, a) =>
                {
                    RaiseExploreFolderClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && Directory.Exists(OutputPath))
                            Process.Start("explorer.exe", $"/select,\"{OutputFilename}\"");
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Explore Folder", "Error while openning the folder", ex.Message);
                    }
                };

            //Details. Usually when something wrong happens.
            if (detailsButton != null)
                detailsButton.Click += (s, a) =>
                {
                    if (Exception != null)
                    {
                        var viewer = new ExceptionViewer(Exception);
                        viewer.ShowDialog();
                    }  
                };

            //Copy (as image and text).
            if (copyMenu != null)
                copyMenu.Click += (s, a) => 
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        var data = new DataObject();
                        data.SetImage(OutputFilename.SourceFrom());
                        data.SetText(OutputFilename, TextDataFormat.Text);
                        data.SetFileDropList(new StringCollection { OutputFilename });

                        Clipboard.SetDataObject(data, true);
                    }
                };

            //Copy as image.
            if (copyImageMenu != null)
                copyImageMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                        Clipboard.SetImage(OutputFilename.SourceFrom());
                };

            //Copy full path.
            if (copyFilenameMenu != null)
                copyFilenameMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                        Clipboard.SetText(OutputFilename);
                };

            //Copy folder path.
            if (copyFolderMenu != null)
                copyFolderMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputPath))
                        Clipboard.SetText(OutputPath);
                };
        }
Example #15
0
 private void btnClipboardImage_Click(object sender, RoutedEventArgs e)
 {
     Clipboard.SetImage(_bitmapImage);
 }
Example #16
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var cancelButton     = Template.FindName("CancelButton", this) as ImageButton;
            var fileButton       = Template.FindName("FileButton", this) as ImageButton;
            var folderButton     = Template.FindName("FolderButton", this) as ImageButton;
            var detailsButton    = Template.FindName("DetailsButton", this) as ImageButton;
            var copyMenu         = Template.FindName("CopyMenuItem", this) as ImageMenuItem;
            var copyImageMenu    = Template.FindName("CopyImageMenuItem", this) as ImageMenuItem;
            var copyFilenameMenu = Template.FindName("CopyFilenameMenuItem", this) as ImageMenuItem;
            var copyFolderMenu   = Template.FindName("CopyFolderMenuItem", this) as ImageMenuItem;

            if (cancelButton != null)
            {
                cancelButton.Click += (s, a) => RaiseCancelClickedEvent();
            }

            if (fileButton != null)
            {
                fileButton.Click += (s, a) =>
                {
                    RaiseOpenFileClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && File.Exists(OutputFilename))
                        {
                            Process.Start(OutputFilename);
                        }
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Open File", "Error while openning the file", ex.Message);
                    }
                }
            }
            ;

            if (folderButton != null)
            {
                folderButton.Click += (s, a) =>
                {
                    RaiseExploreFolderClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && Directory.Exists(OutputPath))
                        {
                            Process.Start("explorer.exe", $"/select,\"{OutputFilename}\"");
                        }
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Explore Folder", "Error while openning the folder", ex.Message);
                    }
                }
            }
            ;

            if (detailsButton != null)
            {
                detailsButton.Click += (s, a) =>
                {
                    if (Exception != null)
                    {
                        var viewer = new ExceptionViewer(Exception);
                        viewer.ShowDialog();
                    }
                }
            }
            ;

            if (copyMenu != null)
            {
                copyMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetFileDropList(new StringCollection {
                            OutputFilename
                        });
                    }
                }
            }
            ;

            if (copyImageMenu != null)
            {
                copyImageMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetImage(OutputFilename.SourceFrom());
                    }
                }
            }
            ;

            if (copyFilenameMenu != null)
            {
                copyFilenameMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetText(OutputFilename);
                    }
                }
            }
            ;

            if (copyFolderMenu != null)
            {
                copyFolderMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputPath))
                    {
                        Clipboard.SetText(OutputPath);
                    }
                }
            }
            ;
        }