Пример #1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var result = SnippingTool.TakeSnippet();

            if (result == null)
            {
                Close();
                return;
            }

            WindowState = WindowState.Normal;

            var rect = result.SelectedRectangle;
            // reposition the window so there's a neat effect of showing
            // the screenshot edit window in place of the selected region

            var top  = rect.Top - 80 + SystemInformation.VirtualScreen.Top;
            var left = rect.Left - 80 + SystemInformation.VirtualScreen.Left;

            rect.Y = rect.Top - 80 + SystemInformation.VirtualScreen.Top;
            rect.X = rect.Left - 80 + SystemInformation.VirtualScreen.Left;

            var    screen = Screen.GetBounds(rect);
            Matrix m      = System.Windows.PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
            double dx     = m.M11;
            double dy     = m.M22;

            Top  = top < screen.Top ? (screen.Top / dy) : (top / dy);
            Left = left < screen.Left ? (screen.Left / dx) : (left / dx);

            var image = result.Image;

            ImageBrush.ImageSource = result.ImageToBitmapSource();

            var width = 400;

            // adjust window size to be slightly larger than
            // the image so nothing is cropped
            if (image.Width > width && image.Width > Width)
            {
                width = image.Width + 100;
            }

            var height = 300;

            if (image.Height > height && image.Height > Height)
            {
                height = image.Height + 100;
            }

            Width  = width;
            Height = height;

            // adjust canvas that is hosting the image to match the image size
            InkCanvas.Width  = image.Width;
            InkCanvas.Height = image.Height;
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var result = SnippingTool.TakeSnippet();

            if (result == null)
            {
                Close();
                return;
            }

            WindowState = WindowState.Normal;

            var rect = result.SelectedRectangle;

            // reposition the window so there's a neat effect of showing
            // the screenshot edit window in place of the selected region
            var top  = rect.Top - 80;
            var left = rect.Left - 80;

            Top  = top > 0 ? top : 0;
            Left = left > 0 ? left : 0;

            var image = result.Image;

            ImageBrush.ImageSource = result.ImageToBitmapSource();

            var width = 400;

            // adjust window size to be slightly larger than
            // the image so nothing is cropped
            if (image.Width > width && image.Width > Width)
            {
                width = image.Width + 100;
            }

            var height = 300;

            if (image.Height > height && image.Height > Height)
            {
                height = image.Height + 100;
            }

            Width  = width;
            Height = height;

            // adjust canvas that is hosting the image to match the image size
            InkCanvas.Width  = image.Width;
            InkCanvas.Height = image.Height;
        }