static private TwoPoints DeduceTopLeftAndBottomRightPoints(TwoPoints twoPoints)
        {
            var result = new TwoPoints();

            result.One.X = twoPoints.One.X < twoPoints.Two.X ? twoPoints.One.X : twoPoints.Two.X;
            result.One.Y = twoPoints.One.Y < twoPoints.Two.Y ? twoPoints.One.Y : twoPoints.Two.Y;
            result.Two.X = twoPoints.One.X > twoPoints.Two.X ? twoPoints.One.X : twoPoints.Two.X;
            result.Two.Y = twoPoints.One.Y > twoPoints.Two.Y ? twoPoints.One.Y : twoPoints.Two.Y;

            return(result);
        }
        private void CopyImageSelection()
        {
            TwoPoints openFrame = DeduceTopLeftAndBottomRightPoints(new TwoPoints(DragMouseStart, DragMouseCurrent));

            if (openFrame.One != openFrame.Two)
            {
                CroppedBitmap cb = new CroppedBitmap((BitmapSource)this.CopiedImage.Source, new Int32Rect((int)openFrame.One.X, (int)openFrame.One.Y, (int)(openFrame.Two.X - openFrame.One.X), (int)(openFrame.Two.Y - openFrame.One.Y)));

                ((MainWindow)this.Owner).CreateImageFromBitmap(cb);
                ((MainWindow)this.Owner).CloseCaptureWindow();
            }
        }
        private void UpdateAllGreyingRectanglesPosition()
        {
            if (this.GreyTop == null)
            {
                void CreateAllGreyingRectangles()
                {
                    Rectangle CreateOneGreyingRectanble()
                    {
                        var rectangle = new Rectangle();

                        rectangle.Fill = Utils.Globals.GreyAndAlphaBrush;
                        return(rectangle);
                    }

                    this.GreyTop    = CreateOneGreyingRectanble();
                    this.GreyLeft   = CreateOneGreyingRectanble();
                    this.GreyRight  = CreateOneGreyingRectanble();
                    this.GreyBottom = CreateOneGreyingRectanble();

                    this.CapturingCanvas.Children.Add(this.GreyTop);
                    this.CapturingCanvas.Children.Add(this.GreyLeft);
                    this.CapturingCanvas.Children.Add(this.GreyRight);
                    this.CapturingCanvas.Children.Add(this.GreyBottom);
                }

                CreateAllGreyingRectangles();
            }

            //this.DebugOutput.Text = string.Format("[{0},{1}] [{2},{3}]", DragMouseStart.X, DragMouseStart.Y, DragMouseCurrent.X, DragMouseCurrent.Y);

            TwoPoints openFrame = DeduceTopLeftAndBottomRightPoints(new TwoPoints(DragMouseStart, DragMouseCurrent));

            this.GreyTop.Width  = this.CopiedImage.ActualWidth;
            this.GreyTop.Height = openFrame.One.Y;
            Canvas.SetLeft(this.GreyTop, 0);
            Canvas.SetTop(this.GreyTop, 0);

            this.GreyLeft.Width  = openFrame.One.X;
            this.GreyLeft.Height = this.CopiedImage.ActualHeight - openFrame.One.Y;
            Canvas.SetLeft(this.GreyLeft, 0);
            Canvas.SetTop(this.GreyLeft, openFrame.One.Y);

            this.GreyRight.Width  = this.CopiedImage.ActualWidth - openFrame.Two.X;
            this.GreyRight.Height = this.CopiedImage.ActualHeight - openFrame.One.Y;
            Canvas.SetLeft(this.GreyRight, openFrame.Two.X);
            Canvas.SetTop(this.GreyRight, openFrame.One.Y);

            this.GreyBottom.Width  = openFrame.Two.X - openFrame.One.X;
            this.GreyBottom.Height = this.CopiedImage.ActualHeight - openFrame.Two.Y;
            Canvas.SetLeft(this.GreyBottom, openFrame.One.X);
            Canvas.SetTop(this.GreyBottom, openFrame.Two.Y);
        }