Exemplo n.º 1
0
        private void Initialize()
        {
            topLeftThumb.ManipulationMode = topRightThumb.ManipulationMode = bottomLeftThumb.ManipulationMode = bottomRightThumb.ManipulationMode =
                ManipulationModes.TranslateX | ManipulationModes.TranslateY;

            //Thumb width and height is 20.
            CropSelection = new CropSelection {
                MinSelectRegionSize = 2 * 30, CropAspectRatio = CropAspectRatio
            };
            imageCanvas.DataContext  = CropSelection;
            scrollViewer.DataContext = CropSelection;
        }
Exemplo n.º 2
0
        private void SourceImage_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (e.NewSize.IsEmpty || double.IsNaN(e.NewSize.Height) || e.NewSize.Height <= 0)
            {
                this.imageCanvas.Visibility = Visibility.Collapsed;
                CropSelection.OuterRect     = Rect.Empty;

                CropSelection.SelectedRect = new Rect(0, 0, 0, 0);
            }
            else
            {
                this.imageCanvas.Visibility = Visibility.Visible;

                this.imageCanvas.Height = e.NewSize.Height;
                this.imageCanvas.Width  = e.NewSize.Width;
                CropSelection.OuterRect = new Rect(0, 0, e.NewSize.Width, e.NewSize.Height);

                if (e.PreviousSize.IsEmpty || double.IsNaN(e.PreviousSize.Height) || e.PreviousSize.Height <= 0)
                {
                    var rect = new Rect();
                    if (CropAspectRatio == AspectRatio.Custom)
                    {
                        rect.Width  = e.NewSize.Width / (int)DefaultCropSelectionSize;
                        rect.Height = e.NewSize.Height / (int)DefaultCropSelectionSize;
                    }
                    else
                    {
                        var min = Math.Min(e.NewSize.Width, e.NewSize.Height);
                        rect.Width = rect.Height = min / (int)DefaultCropSelectionSize;
                    }

                    rect.X = (e.NewSize.Width - rect.Width) / (int)DefaultCropSelectionSize;
                    rect.Y = (e.NewSize.Height - rect.Height) / (int)DefaultCropSelectionSize;

                    CropSelection.SelectedRect = rect;
                }
                else
                {
                    double scale = e.NewSize.Height / e.PreviousSize.Height;
                    //todo
                    CropSelection.ResizeSelectedRect(scale);
                }
            }
        }
Exemplo n.º 3
0
        void ResizeCropSelection(Size newSize, Size previousSize)
        {
            double scale = newSize.Height / previousSize.Height;

            CropSelection.ResizeSelectedRect(scale);
        }