public void SetImage(System.Drawing.Bitmap bitmap_)
 {
     using (var bitmap = new Movable <System.Drawing.Bitmap>(bitmap_))
     {
         using (var safeHandle = new SafeHBitmapHandle(bitmap.Get().GetHbitmap()))
         {
             this.CopiedImage.Source = Imaging.CreateBitmapSourceFromHBitmap(safeHandle.Handle, IntPtr.Zero, Int32Rect.Empty,
                                                                             BitmapSizeOptions.FromEmptyOptions());
         }
     }
     this.SizeToContent = SizeToContent.WidthAndHeight;
 }
Пример #2
0
 private void CaptureFromDiskButton_Click(object sender, RoutedEventArgs e)
 {
     using (var screenshot = new Utils.Movable <System.Drawing.Bitmap>(Utils.ScreenShooting.LoadImage()))
     {
         if (screenshot.Get() != null)
         {
             var imageWindow = new Utils.CapturedImage();
             this.imageWindows.Add(imageWindow);
             imageWindow.Owner = this;
             imageWindow.SetImage(screenshot.Release());
             imageWindow.SetName(this.GenerateNewImageName());
             imageWindow.Show();
         }
     }
 }
        public void SetImage(System.Drawing.Bitmap bitmap_)
        {
            using (var bitmap = new Movable <System.Drawing.Bitmap>(bitmap_))
            {
                using (var safeHandle = new SafeHBitmapHandle(bitmap.Get().GetHbitmap()))
                {
                    this.CopiedImage.Source = Imaging.CreateBitmapSourceFromHBitmap(safeHandle.Handle, IntPtr.Zero, Int32Rect.Empty,
                                                                                    BitmapSizeOptions.FromEmptyOptions());
                }
            }

            this.CapturingCanvas.Children.Add(this.CopiedImage);
            //var t = new TextBox();
            //t.Text = string.Format("{0}-{1} / {2}-{3}", this.Left, this.Top, this.Width, this.Height);
            //this.CapturingCanvas.Children.Add(t);
        }
Пример #4
0
 private void CaptureFromClipboard()
 {
     try
     {
         using (var screenshot = new Utils.Movable <System.Drawing.Bitmap>(Utils.ScreenShooting.CaptureImageFromClipboard()))
         {
             var imageWindow = new Utils.CapturedImage();
             this.imageWindows.Add(imageWindow);
             imageWindow.Owner = this;
             imageWindow.SetImage(screenshot.Release());
             imageWindow.SetName(this.GenerateNewImageName());
             imageWindow.Show();
         }
     }
     catch (System.NullReferenceException)
     {
         MessageBox.Show("There is no valid image in the Clipboard", "Failure", MessageBoxButton.OK);
     }
 }
Пример #5
0
        static public Drawing.Bitmap CaptureImageFromFullScreen()
        {
            // Source: https://stackoverflow.com/a/15862043/14089

            // Determine the size of the "virtual screen", which includes all monitors.
            int screenLeft   = (int)SystemParameters.VirtualScreenLeft;
            int screenTop    = (int)SystemParameters.VirtualScreenTop;
            int screenWidth  = (int)SystemParameters.VirtualScreenWidth;
            int screenHeight = (int)SystemParameters.VirtualScreenHeight;

            // Create a bitmap of the appropriate size to receive the screenshot.
            using (var bitmap = new Movable <Drawing.Bitmap>(new Drawing.Bitmap(screenWidth, screenHeight)))
            {
                // Draw the screenshot into our bitmap.
                using (var g = Drawing.Graphics.FromImage(bitmap.Get()))
                {
                    g.CopyFromScreen(screenLeft, screenTop, 0, 0, bitmap.Get().Size);
                }
                return(bitmap.Release());
            }
        }
Пример #6
0
        private void CaptureFromScreenButton_Click(object sender, RoutedEventArgs e)
        {
            if ((this.captureWindow != null) && (this.captureWindow.IsClosed))
            {
                this.captureWindow = null;
            }

            if (this.captureWindow == null)
            {
                using (var scopedHideShow = new Utils.ScopedHideShow(this))
                {
                    int delay = 1000 * int.Parse(((ComboBoxItem)this.DelayComboBox.SelectedItem)?.Tag?.ToString() ?? "0");
                    Thread.Sleep(500 + delay); // TODO This is both ugly and wrong. Wait for asynchronous "hidden" event instead. This will complicate scoped handling.
                    using (var screenshot = new Utils.Movable <System.Drawing.Bitmap>(Utils.ScreenShooting.CaptureImageFromFullScreen()))
                    {
                        this.captureWindow       = new Utils.CapturingImage();
                        this.captureWindow.Owner = this;
                        this.captureWindow.SetImage(screenshot.Release());
                        this.captureWindow.Show();
                    }
                }
            }
        }
Пример #7
0
 public Movable(Movable <T> that)
 {
     this.resource = that.Release();
 }