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); } } }
void ResizeCropSelection(Size newSize, Size previousSize) { double scale = newSize.Height / previousSize.Height; CropSelection.ResizeSelectedRect(scale); }