Example #1
0
        private void DrawSelect_MouseUp()
        {
            if (SelectRectangle != null && currentSelectedImage == null)
            {
                if (SelectRectangle.Height < 2 || SelectRectangle.Width < 2)
                {
                    paintCanvas.Children.Remove(SelectRectangle);
                    SelectRectangle = null;
                }
                else
                {
                    paintCanvas.Children.Remove(SelectRectangle);
                    currentSelectedImage = CanvasUltilities.Crop(paintCanvas, Canvas.GetLeft(SelectRectangle), Canvas.GetTop(SelectRectangle), SelectRectangle.Width, SelectRectangle.Height);

                    //Add replace rectangle to Hide view behind cropped region
                    Rectangle replace = new Rectangle()
                    {
                        Width           = SelectRectangle.Width,
                        Height          = SelectRectangle.Height,
                        Stroke          = Brushes.Transparent,
                        StrokeThickness = 0,
                        Fill            = Brushes.White
                    };
                    Canvas.SetLeft(replace, Canvas.GetLeft(SelectRectangle));
                    Canvas.SetTop(replace, Canvas.GetTop(SelectRectangle));
                    paintCanvas.Children.Add(replace);


                    currentSelectedImage.Stretch          = Stretch.Fill;
                    currentSelectedImage.StretchDirection = StretchDirection.Both;
                    Canvas.SetLeft(currentSelectedImage, Canvas.GetLeft(SelectRectangle));
                    Canvas.SetTop(currentSelectedImage, Canvas.GetTop(SelectRectangle));
                    currentSelectedImage.Width  = currentSelectedImage.Source.Width;
                    currentSelectedImage.Height = currentSelectedImage.Source.Height;

                    paintCanvas.Children.Add(currentSelectedImage);
                    Adorner image_adorner = new SelectAdorner(currentSelectedImage);
                    adlayer.Add(image_adorner);
                }
            }
        }
Example #2
0
 private Image paintCanvas_CropAt(int x, int y, double w, double h)
 {
     return(CanvasUltilities.Crop(paintCanvas, x, y, w, h));
 }