From bbed16ef82af955f0a3705bd79605aee2481a5a3 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 10 Aug 2022 18:48:47 -0500 Subject: [PATCH 01/13] Fixed AspectRatio on ImageCropper not updating when image is loaded or resized --- .../ImageCropper/ImageCropper.Events.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs index a8a7109c735..aa0c2820995 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs @@ -173,6 +173,7 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) UpdateImageLayout(); UpdateMaskArea(); + UpdateAspectRatio(true); } } } \ No newline at end of file From c0b2ec59d4f9c0393614dcf077b8942a43e9941d Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 17 Aug 2022 12:07:52 -0500 Subject: [PATCH 02/13] Removed uneeded resize animation --- .../ImageCropper/ImageCropper.Events.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs index aa0c2820995..7f189653e30 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs @@ -173,7 +173,7 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) UpdateImageLayout(); UpdateMaskArea(); - UpdateAspectRatio(true); + UpdateAspectRatio(); } } } \ No newline at end of file From b09ecc6ed5c08acfe6bcef3e90f82e2e7d5ed16e Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Sep 2022 19:16:59 -0500 Subject: [PATCH 03/13] Added notes and cleaned up code --- .../ImageCropper/ImageCropper.Logic.cs | 152 ++++++++++-------- .../ImageCropper/ImageCropper.cs | 44 +++-- 2 files changed, 116 insertions(+), 80 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs index 47f87baed84..7891bdf10cd 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs @@ -28,7 +28,7 @@ private void InitImageLayout(bool animate = false) _restrictedCropRect = new Rect(0, 0, Source.PixelWidth, Source.PixelHeight); if (IsValidRect(_restrictedCropRect)) { - _currentCroppedRect = KeepAspectRatio ? GetUniformRect(_restrictedCropRect, UsedAspectRatio) : _restrictedCropRect; + _currentCroppedRect = KeepAspectRatio ? GetUniformRect(_restrictedCropRect, ActualAspectRatio) : _restrictedCropRect; UpdateImageLayout(animate); } } @@ -36,13 +36,15 @@ private void InitImageLayout(bool animate = false) UpdateThumbsVisibility(); } + private bool ShouldUpdateImageLayout => Source != null && IsValidRect(CanvasRect); + /// /// Update image source transform. /// /// Whether animation is enabled. private void UpdateImageLayout(bool animate = false) { - if (Source != null && IsValidRect(CanvasRect)) + if (ShouldUpdateImageLayout) { var uniformSelectedRect = GetUniformRect(CanvasRect, _currentCroppedRect.Width / _currentCroppedRect.Height); UpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate); @@ -105,7 +107,7 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) double radian = 0d, diffPointRadian = 0d; if (KeepAspectRatio) { - radian = Math.Atan(UsedAspectRatio); + radian = Math.Atan(ActualAspectRatio); diffPointRadian = Math.Atan(diffPos.X / diffPos.Y); } @@ -117,8 +119,8 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) case ThumbPosition.Top: if (KeepAspectRatio) { - var originSizeChange = new Point(-diffPos.Y * UsedAspectRatio, -diffPos.Y); - var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, UsedAspectRatio); + var originSizeChange = new Point(-diffPos.Y * ActualAspectRatio, -diffPos.Y); + var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, ActualAspectRatio); startPoint.X += -safeChange.X / 2; endPoint.X += safeChange.X / 2; startPoint.Y += -safeChange.Y; @@ -132,8 +134,8 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) case ThumbPosition.Bottom: if (KeepAspectRatio) { - var originSizeChange = new Point(diffPos.Y * UsedAspectRatio, diffPos.Y); - var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, UsedAspectRatio); + var originSizeChange = new Point(diffPos.Y * ActualAspectRatio, diffPos.Y); + var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, ActualAspectRatio); startPoint.X += -safeChange.X / 2; endPoint.X += safeChange.X / 2; endPoint.Y += safeChange.Y; @@ -147,8 +149,8 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) case ThumbPosition.Left: if (KeepAspectRatio) { - var originSizeChange = new Point(-diffPos.X, -diffPos.X / UsedAspectRatio); - var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, UsedAspectRatio); + var originSizeChange = new Point(-diffPos.X, -diffPos.X / ActualAspectRatio); + var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, ActualAspectRatio); startPoint.Y += -safeChange.Y / 2; endPoint.Y += safeChange.Y / 2; startPoint.X += -safeChange.X; @@ -162,8 +164,8 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) case ThumbPosition.Right: if (KeepAspectRatio) { - var originSizeChange = new Point(diffPos.X, diffPos.X / UsedAspectRatio); - var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, UsedAspectRatio); + var originSizeChange = new Point(diffPos.X, diffPos.X / ActualAspectRatio); + var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, ActualAspectRatio); startPoint.Y += -safeChange.Y / 2; endPoint.Y += safeChange.Y / 2; endPoint.X += safeChange.X; @@ -179,7 +181,7 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) { var effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian); var originSizeChange = new Point(-effectiveLength * Math.Sin(radian), -effectiveLength * Math.Cos(radian)); - var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, UsedAspectRatio); + var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, ActualAspectRatio); diffPos.X = -safeChange.X; diffPos.Y = -safeChange.Y; } @@ -193,7 +195,7 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) diffPointRadian = -diffPointRadian; var effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian); var originSizeChange = new Point(-effectiveLength * Math.Sin(radian), -effectiveLength * Math.Cos(radian)); - var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, UsedAspectRatio); + var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, ActualAspectRatio); diffPos.X = safeChange.X; diffPos.Y = -safeChange.Y; } @@ -207,7 +209,7 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) diffPointRadian = -diffPointRadian; var effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian); var originSizeChange = new Point(effectiveLength * Math.Sin(radian), effectiveLength * Math.Cos(radian)); - var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, UsedAspectRatio); + var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, ActualAspectRatio); diffPos.X = -safeChange.X; diffPos.Y = safeChange.Y; } @@ -220,7 +222,7 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) { var effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian); var originSizeChange = new Point(effectiveLength * Math.Sin(radian), effectiveLength * Math.Cos(radian)); - var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, UsedAspectRatio); + var safeChange = GetSafeSizeChangeWhenKeepAspectRatio(_restrictedSelectRect, position, currentSelectedRect, originSizeChange, ActualAspectRatio); diffPos.X = safeChange.X; diffPos.Y = safeChange.Y; } @@ -293,8 +295,8 @@ private void UpdateSelectedRect(Point startPoint, Point endPoint, bool animate = _startY = startPoint.Y; _endX = endPoint.X; _endY = endPoint.Y; - var centerX = ((_endX - _startX) / 2) + _startX; - var centerY = ((_endY - _startY) / 2) + _startY; + var center = SelectionAreaCenter; + Storyboard storyboard = null; if (animate) { @@ -305,12 +307,12 @@ private void UpdateSelectedRect(Point startPoint, Point endPoint, bool animate = { if (animate) { - storyboard.Children.Add(CreateDoubleAnimation(centerX, _animationDuration, _topThumb, nameof(ImageCropperThumb.X), true)); + storyboard.Children.Add(CreateDoubleAnimation(center.X, _animationDuration, _topThumb, nameof(ImageCropperThumb.X), true)); storyboard.Children.Add(CreateDoubleAnimation(_startY, _animationDuration, _topThumb, nameof(ImageCropperThumb.Y), true)); } else { - _topThumb.X = centerX; + _topThumb.X = center.X; _topThumb.Y = _startY; } } @@ -319,12 +321,12 @@ private void UpdateSelectedRect(Point startPoint, Point endPoint, bool animate = { if (animate) { - storyboard.Children.Add(CreateDoubleAnimation(centerX, _animationDuration, _bottomThumb, nameof(ImageCropperThumb.X), true)); + storyboard.Children.Add(CreateDoubleAnimation(center.X, _animationDuration, _bottomThumb, nameof(ImageCropperThumb.X), true)); storyboard.Children.Add(CreateDoubleAnimation(_endY, _animationDuration, _bottomThumb, nameof(ImageCropperThumb.Y), true)); } else { - _bottomThumb.X = centerX; + _bottomThumb.X = center.X; _bottomThumb.Y = _endY; } } @@ -334,12 +336,12 @@ private void UpdateSelectedRect(Point startPoint, Point endPoint, bool animate = if (animate) { storyboard.Children.Add(CreateDoubleAnimation(_startX, _animationDuration, _leftThumb, nameof(ImageCropperThumb.X), true)); - storyboard.Children.Add(CreateDoubleAnimation(centerY, _animationDuration, _leftThumb, nameof(ImageCropperThumb.Y), true)); + storyboard.Children.Add(CreateDoubleAnimation(center.Y, _animationDuration, _leftThumb, nameof(ImageCropperThumb.Y), true)); } else { _leftThumb.X = _startX; - _leftThumb.Y = centerY; + _leftThumb.Y = center.Y; } } @@ -348,12 +350,12 @@ private void UpdateSelectedRect(Point startPoint, Point endPoint, bool animate = if (animate) { storyboard.Children.Add(CreateDoubleAnimation(_endX, _animationDuration, _rightThumb, nameof(ImageCropperThumb.X), true)); - storyboard.Children.Add(CreateDoubleAnimation(centerY, _animationDuration, _rightThumb, nameof(ImageCropperThumb.Y), true)); + storyboard.Children.Add(CreateDoubleAnimation(center.Y, _animationDuration, _rightThumb, nameof(ImageCropperThumb.Y), true)); } else { _rightThumb.X = _endX; - _rightThumb.Y = centerY; + _rightThumb.Y = center.Y; } } @@ -504,61 +506,74 @@ private void UpdateMaskArea(bool animate = false) }; } + private bool ShouldUpdateAspectRatio => KeepAspectRatio && Source != null && IsValidRect(_restrictedSelectRect); + /// /// Update image aspect ratio. /// private void UpdateAspectRatio(bool animate = false) { - if (KeepAspectRatio && Source != null && IsValidRect(_restrictedSelectRect)) - { - var centerX = ((_endX - _startX) / 2) + _startX; - var centerY = ((_endY - _startY) / 2) + _startY; - var restrictedMinLength = MinCroppedPixelLength * _imageTransform.ScaleX; - var maxSelectedLength = Math.Max(_endX - _startX, _endY - _startY); - var viewRect = new Rect(centerX - (maxSelectedLength / 2), centerY - (maxSelectedLength / 2), maxSelectedLength, maxSelectedLength); - var uniformSelectedRect = GetUniformRect(viewRect, UsedAspectRatio); - if (uniformSelectedRect.Width > _restrictedSelectRect.Width || uniformSelectedRect.Height > _restrictedSelectRect.Height) - { - uniformSelectedRect = GetUniformRect(_restrictedSelectRect, UsedAspectRatio); - } + if (!ShouldUpdateAspectRatio) + { + return; + } - if (uniformSelectedRect.Width < restrictedMinLength || uniformSelectedRect.Height < restrictedMinLength) - { - var scale = restrictedMinLength / Math.Min(uniformSelectedRect.Width, uniformSelectedRect.Height); - uniformSelectedRect.Width *= scale; - uniformSelectedRect.Height *= scale; - if (uniformSelectedRect.Width > _restrictedSelectRect.Width || uniformSelectedRect.Height > _restrictedSelectRect.Height) - { - AspectRatio = -1; - return; - } - } + var center = SelectionAreaCenter; + var restrictedMinLength = MinCroppedPixelLength * _imageTransform.ScaleX; + var maxSelectedLength = Math.Max(_endX - _startX, _endY - _startY); + var viewRect = new Rect(center.X - (maxSelectedLength / 2), center.Y - (maxSelectedLength / 2), maxSelectedLength, maxSelectedLength); - if (_restrictedSelectRect.X > uniformSelectedRect.X) - { - uniformSelectedRect.X += _restrictedSelectRect.X - uniformSelectedRect.X; - } + var uniformSelectedRect = GetUniformRect(viewRect, ActualAspectRatio); + if (uniformSelectedRect.Width > _restrictedSelectRect.Width || uniformSelectedRect.Height > _restrictedSelectRect.Height) + { + uniformSelectedRect = GetUniformRect(_restrictedSelectRect, ActualAspectRatio); + } - if (_restrictedSelectRect.Y > uniformSelectedRect.Y) - { - uniformSelectedRect.Y += _restrictedSelectRect.Y - uniformSelectedRect.Y; - } + // If selection area is smaller than allowed. + if (uniformSelectedRect.Width < restrictedMinLength || uniformSelectedRect.Height < restrictedMinLength) + { + // Scale selection area to fit. + var scale = restrictedMinLength / Math.Min(uniformSelectedRect.Width, uniformSelectedRect.Height); + uniformSelectedRect.Width *= scale; + uniformSelectedRect.Height *= scale; - if ((_restrictedSelectRect.X + _restrictedSelectRect.Width) < (uniformSelectedRect.X + uniformSelectedRect.Width)) + // If selection area is larger than allowed. + if (uniformSelectedRect.Width > _restrictedSelectRect.Width || uniformSelectedRect.Height > _restrictedSelectRect.Height) { - uniformSelectedRect.X += (_restrictedSelectRect.X + _restrictedSelectRect.Width) - (uniformSelectedRect.X + uniformSelectedRect.Width); + // Sentinal value. Equivelant to setting KeepAspectRatio to false. Causes AspectRatio to be recalculated. + AspectRatio = -1; + return; } + } - if ((_restrictedSelectRect.Y + _restrictedSelectRect.Height) < (uniformSelectedRect.Y + uniformSelectedRect.Height)) - { - uniformSelectedRect.Y += (_restrictedSelectRect.Y + _restrictedSelectRect.Height) - (uniformSelectedRect.Y + uniformSelectedRect.Height); - } + // Fix positioning + if (_restrictedSelectRect.X > uniformSelectedRect.X) + { + uniformSelectedRect.X += _restrictedSelectRect.X - uniformSelectedRect.X; + } - var croppedRect = _inverseImageTransform.TransformBounds(uniformSelectedRect); - croppedRect.Intersect(_restrictedCropRect); - _currentCroppedRect = croppedRect; - UpdateImageLayout(animate); + if (_restrictedSelectRect.Y > uniformSelectedRect.Y) + { + uniformSelectedRect.Y += _restrictedSelectRect.Y - uniformSelectedRect.Y; } + + // Fix size + if ((_restrictedSelectRect.X + _restrictedSelectRect.Width) < (uniformSelectedRect.X + uniformSelectedRect.Width)) + { + uniformSelectedRect.X += (_restrictedSelectRect.X + _restrictedSelectRect.Width) - (uniformSelectedRect.X + uniformSelectedRect.Width); + } + + if ((_restrictedSelectRect.Y + _restrictedSelectRect.Height) < (uniformSelectedRect.Y + uniformSelectedRect.Height)) + { + uniformSelectedRect.Y += (_restrictedSelectRect.Y + _restrictedSelectRect.Height) - (uniformSelectedRect.Y + uniformSelectedRect.Height); + } + + // Apply transformation + var croppedRect = _inverseImageTransform.TransformBounds(uniformSelectedRect); + croppedRect.Intersect(_restrictedCropRect); + _currentCroppedRect = croppedRect; + + UpdateImageLayout(animate); } /// @@ -632,5 +647,10 @@ private void UpdateThumbsVisibility() _lowerRigthThumb.Visibility = cornerThumbsVisibility; } } + + /// + /// Gets a value that indicates the center of the visible selection rectangle. + /// + private Point SelectionAreaCenter => new Point(((_endX - _startX) / 2) + _startX, ((_endY - _startY) / 2) + _startY); } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs index 60ed065fbdd..88bffffb512 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs @@ -49,10 +49,13 @@ public partial class ImageCropper : Control private ImageCropperThumb _upperRightThumb; private ImageCropperThumb _lowerLeftThumb; private ImageCropperThumb _lowerRigthThumb; + + // Selection area private double _startX; private double _startY; private double _endX; private double _endY; + private Rect _currentCroppedRect = Rect.Empty; private Rect _restrictedCropRect = Rect.Empty; private Rect _restrictedSelectRect = Rect.Empty; @@ -70,23 +73,36 @@ public ImageCropper() private Rect CanvasRect => new Rect(0, 0, _imageCanvas?.ActualWidth ?? 0, _imageCanvas?.ActualHeight ?? 0); - private bool KeepAspectRatio => UsedAspectRatio > 0; + /// + /// Gets a value indicating whether the user-provided is valid and should be kept during manipulation of the image cropper. + /// + private bool KeepAspectRatio => ActualAspectRatio > 0; - private double UsedAspectRatio + /// + /// Gets the internally used aspect ratio, rather than the user-provided value. Adjusted to handle crop shape and invalid values. + /// + private double ActualAspectRatio { get { - var aspectRatio = AspectRatio; - switch (CropShape) + var aspectRatio = CropShape switch { - case CropShape.Rectangular: - break; - case CropShape.Circular: - aspectRatio = 1; - break; - } + CropShape.Rectangular => AspectRatio, + CropShape.Circular => 1, + _ => AspectRatio, + }; - return aspectRatio != null && aspectRatio > 0 ? aspectRatio.Value : -1; + if (aspectRatio is not null && aspectRatio > 0) + { + // When not null or 0. + return aspectRatio.Value; + } + else + { + // Fallback to sentinal value. + // Used to indicate aspect ratio should be discarded and reset during manipulation of the image cropper. + return -1; + } } } @@ -97,7 +113,7 @@ private Size MinCropSize { get { - var aspectRatio = KeepAspectRatio ? UsedAspectRatio : 1; + var aspectRatio = KeepAspectRatio ? ActualAspectRatio : 1; var size = new Size(MinCroppedPixelLength, MinCroppedPixelLength); if (aspectRatio >= 1) { @@ -123,7 +139,7 @@ private Size MinSelectSize var minLength = Math.Min(realMinSelectSize.Width, realMinSelectSize.Height); if (minLength < MinSelectedLength) { - var aspectRatio = KeepAspectRatio ? UsedAspectRatio : 1; + var aspectRatio = KeepAspectRatio ? ActualAspectRatio : 1; var minSelectSize = new Size(MinSelectedLength, MinSelectedLength); if (aspectRatio >= 1) { @@ -433,7 +449,7 @@ public bool TrySetCroppedRegion(Rect rect) // If an aspect ratio is set, reject regions that don't respect it // If cropping a circle, reject regions where the aspect ratio is not 1 - if (KeepAspectRatio && UsedAspectRatio != rect.Width / rect.Height) + if (KeepAspectRatio && ActualAspectRatio != rect.Width / rect.Height) { return false; } From eaf4de24b7a120bf34f57ace3d8d0f508c0c28ef Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Sep 2022 19:24:26 -0500 Subject: [PATCH 04/13] Extracted UpdateImageLayout call from UpdateAspectRatio --- .../ImageCropper/ImageCropper.Events.cs | 6 +++++- .../ImageCropper/ImageCropper.Logic.cs | 16 ++++++---------- .../ImageCropper/ImageCropper.Properties.cs | 13 +++++++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs index 7f189653e30..cc2fd840090 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs @@ -173,7 +173,11 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) UpdateImageLayout(); UpdateMaskArea(); - UpdateAspectRatio(); + + if (TryUpdateAspectRatio()) + { + UpdateImageLayout(); + } } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs index 7891bdf10cd..f084824cd22 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs @@ -36,15 +36,13 @@ private void InitImageLayout(bool animate = false) UpdateThumbsVisibility(); } - private bool ShouldUpdateImageLayout => Source != null && IsValidRect(CanvasRect); - /// /// Update image source transform. /// /// Whether animation is enabled. private void UpdateImageLayout(bool animate = false) { - if (ShouldUpdateImageLayout) + if (Source != null && IsValidRect(CanvasRect)) { var uniformSelectedRect = GetUniformRect(CanvasRect, _currentCroppedRect.Width / _currentCroppedRect.Height); UpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate); @@ -506,16 +504,14 @@ private void UpdateMaskArea(bool animate = false) }; } - private bool ShouldUpdateAspectRatio => KeepAspectRatio && Source != null && IsValidRect(_restrictedSelectRect); - /// /// Update image aspect ratio. /// - private void UpdateAspectRatio(bool animate = false) + private bool TryUpdateAspectRatio() { - if (!ShouldUpdateAspectRatio) + if (!(KeepAspectRatio && Source != null && IsValidRect(_restrictedSelectRect))) { - return; + return false; } var center = SelectionAreaCenter; @@ -542,7 +538,7 @@ private void UpdateAspectRatio(bool animate = false) { // Sentinal value. Equivelant to setting KeepAspectRatio to false. Causes AspectRatio to be recalculated. AspectRatio = -1; - return; + return false; } } @@ -573,7 +569,7 @@ private void UpdateAspectRatio(bool animate = false) croppedRect.Intersect(_restrictedCropRect); _currentCroppedRect = croppedRect; - UpdateImageLayout(animate); + return true; } /// diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs index f0640486f23..1f7a18bce89 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs @@ -51,7 +51,11 @@ private static void OnAspectRatioChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { var target = (ImageCropper)d; - target.UpdateAspectRatio(true); + + if (target.TryUpdateAspectRatio()) + { + target.UpdateImageLayout(true); + } } private static void OnCropShapeChanged( @@ -60,7 +64,12 @@ private static void OnCropShapeChanged( var target = (ImageCropper)d; target.UpdateCropShape(); target.UpdateThumbsVisibility(); - target.UpdateAspectRatio(); + + if (target.TryUpdateAspectRatio()) + { + target.UpdateImageLayout(); + } + target.UpdateMaskArea(); } From aec742b77bfb92c8c70b4b7a9569e541fa81dd3c Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Sep 2022 19:43:08 -0500 Subject: [PATCH 05/13] Extracted UpdateMaskArea out of UpdatedSelectedRect, renamed to UpdateSelectionThumbs --- .../ImageCropper/ImageCropper.Logic.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs index f084824cd22..358992e445f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs @@ -75,6 +75,7 @@ private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect var endPoint = GetSafePoint(_restrictedSelectRect, new Point( selectedRect.X + selectedRect.Width, selectedRect.Y + selectedRect.Height)); + if (animate) { AnimateUIElementOffset(new Point(_imageTransform.TranslateX, _imageTransform.TranslateY), _animationDuration, _sourceImage); @@ -87,7 +88,8 @@ private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect targetVisual.Scale = new Vector3((float)imageScale); } - UpdateSelectedRect(startPoint, endPoint, animate); + UpdateSelectionThumbs(startPoint, endPoint, animate); + UpdateMaskArea(animate); } /// @@ -277,17 +279,18 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) } else { - UpdateSelectedRect(startPoint, endPoint); + UpdateSelectionThumbs(startPoint, endPoint); + UpdateMaskArea(); } } /// - /// Update selection area. + /// Positions the thumbs for the selection rectangle. /// /// The point on the upper left corner. /// The point on the lower right corner. /// Whether animation is enabled. - private void UpdateSelectedRect(Point startPoint, Point endPoint, bool animate = false) + private void UpdateSelectionThumbs(Point startPoint, Point endPoint, bool animate = false) { _startX = startPoint.X; _startY = startPoint.Y; @@ -417,8 +420,6 @@ private void UpdateSelectedRect(Point startPoint, Point endPoint, bool animate = { storyboard.Begin(); } - - UpdateMaskArea(animate); } /// From 56fd8d1b335c6fd682029dd1e5b85078e638a0a3 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Sep 2022 19:52:47 -0500 Subject: [PATCH 06/13] Extracted UpdateSelectionThumbs and UpdateMaskArea out of UpdateImageLayoutWithViewport --- .../ImageCropper/ImageCropper.Logic.cs | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs index 358992e445f..0dbb9fa7e23 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Net; using System.Numerics; using Windows.Foundation; using Windows.UI.Xaml; @@ -40,13 +41,22 @@ private void InitImageLayout(bool animate = false) /// Update image source transform. /// /// Whether animation is enabled. - private void UpdateImageLayout(bool animate = false) + private bool UpdateImageLayout(bool animate = false) { if (Source != null && IsValidRect(CanvasRect)) { var uniformSelectedRect = GetUniformRect(CanvasRect, _currentCroppedRect.Width / _currentCroppedRect.Height); - UpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate); + + if (TryUpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate)) + { + UpdateSelectionThumbs(animate); + UpdateMaskArea(animate); + } + + return true; } + + return false; } /// @@ -55,11 +65,11 @@ private void UpdateImageLayout(bool animate = false) /// Viewport /// The real image area of viewport. /// Whether animation is enabled. - private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect, bool animate = false) + private bool TryUpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect, bool animate = false) { if (!IsValidRect(viewport) || !IsValidRect(viewportImageRect)) { - return; + return false; } var imageScale = viewport.Width / viewportImageRect.Width; @@ -69,12 +79,7 @@ private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect _inverseImageTransform.ScaleX = _inverseImageTransform.ScaleY = 1 / imageScale; _inverseImageTransform.TranslateX = -_imageTransform.TranslateX / imageScale; _inverseImageTransform.TranslateY = -_imageTransform.TranslateY / imageScale; - var selectedRect = _imageTransform.TransformBounds(_currentCroppedRect); _restrictedSelectRect = _imageTransform.TransformBounds(_restrictedCropRect); - var startPoint = GetSafePoint(_restrictedSelectRect, new Point(selectedRect.X, selectedRect.Y)); - var endPoint = GetSafePoint(_restrictedSelectRect, new Point( - selectedRect.X + selectedRect.Width, - selectedRect.Y + selectedRect.Height)); if (animate) { @@ -88,8 +93,7 @@ private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect targetVisual.Scale = new Vector3((float)imageScale); } - UpdateSelectionThumbs(startPoint, endPoint, animate); - UpdateMaskArea(animate); + return true; } /// @@ -275,7 +279,12 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) _currentCroppedRect = croppedRect; var viewportRect = GetUniformRect(CanvasRect, selectedRect.Width / selectedRect.Height); var viewportImgRect = _inverseImageTransform.TransformBounds(selectedRect); - UpdateImageLayoutWithViewport(viewportRect, viewportImgRect); + + if (TryUpdateImageLayoutWithViewport(viewportRect, viewportImgRect)) + { + UpdateSelectionThumbs(); + UpdateMaskArea(); + } } else { @@ -284,6 +293,15 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos) } } + private void UpdateSelectionThumbs(bool animate = false) + { + var selectedRect = _imageTransform.TransformBounds(_currentCroppedRect); + var startPoint = GetSafePoint(_restrictedSelectRect, new Point(selectedRect.X, selectedRect.Y)); + var endPoint = GetSafePoint(_restrictedSelectRect, new Point(selectedRect.X + selectedRect.Width, selectedRect.Y + selectedRect.Height)); + + UpdateSelectionThumbs(startPoint, endPoint, animate); + } + /// /// Positions the thumbs for the selection rectangle. /// From 16d28978fab5efae87e8a641087a8ba402c1b0cc Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Sep 2022 19:59:58 -0500 Subject: [PATCH 07/13] Exracted UpdateSelectionThumbs and UpdateMaskArea out of TryUpdateImageLayout --- .../ImageCropper/ImageCropper.Events.cs | 32 ++++++++++++++++--- .../ImageCropper/ImageCropper.Logic.cs | 17 +++++----- .../ImageCropper/ImageCropper.Properties.cs | 12 +++++-- .../ImageCropper/ImageCropper.cs | 7 +++- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs index cc2fd840090..5f659c0a7c5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs @@ -106,7 +106,11 @@ private void ImageCropperThumb_KeyUp(object sender, KeyRoutedEventArgs e) _currentCroppedRect = croppedRect; } - UpdateImageLayout(true); + if (TryUpdateImageLayout(true)) + { + UpdateSelectionThumbs(true); + UpdateMaskArea(true); + } } private void ImageCropperThumb_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) @@ -119,7 +123,11 @@ private void ImageCropperThumb_ManipulationCompleted(object sender, Manipulation _currentCroppedRect = croppedRect; } - UpdateImageLayout(true); + if (TryUpdateImageLayout(true)) + { + UpdateSelectionThumbs(true); + UpdateMaskArea(true); + } } private void ImageCropperThumb_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) @@ -161,7 +169,12 @@ private void SourceImage_ManipulationDelta(object sender, ManipulationDeltaRoute var croppedRect = _inverseImageTransform.TransformBounds(selectedRect); croppedRect.Intersect(_restrictedCropRect); _currentCroppedRect = croppedRect; - UpdateImageLayout(); + + if (TryUpdateImageLayout()) + { + UpdateSelectionThumbs(); + UpdateMaskArea(); + } } private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) @@ -171,12 +184,21 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) return; } - UpdateImageLayout(); + if (TryUpdateImageLayout()) + { + UpdateSelectionThumbs(); + UpdateMaskArea(); + } + UpdateMaskArea(); if (TryUpdateAspectRatio()) { - UpdateImageLayout(); + if (TryUpdateImageLayout()) + { + UpdateSelectionThumbs(); + UpdateMaskArea(); + } } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs index 0dbb9fa7e23..d1a51837e6f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs @@ -30,7 +30,12 @@ private void InitImageLayout(bool animate = false) if (IsValidRect(_restrictedCropRect)) { _currentCroppedRect = KeepAspectRatio ? GetUniformRect(_restrictedCropRect, ActualAspectRatio) : _restrictedCropRect; - UpdateImageLayout(animate); + + if (TryUpdateImageLayout(animate)) + { + UpdateSelectionThumbs(animate); + UpdateMaskArea(animate); + } } } @@ -41,19 +46,13 @@ private void InitImageLayout(bool animate = false) /// Update image source transform. /// /// Whether animation is enabled. - private bool UpdateImageLayout(bool animate = false) + private bool TryUpdateImageLayout(bool animate = false) { if (Source != null && IsValidRect(CanvasRect)) { var uniformSelectedRect = GetUniformRect(CanvasRect, _currentCroppedRect.Width / _currentCroppedRect.Height); - if (TryUpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate)) - { - UpdateSelectionThumbs(animate); - UpdateMaskArea(animate); - } - - return true; + return TryUpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate); } return false; diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs index 1f7a18bce89..d506753dfe5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs @@ -54,7 +54,11 @@ private static void OnAspectRatioChanged( if (target.TryUpdateAspectRatio()) { - target.UpdateImageLayout(true); + if (target.TryUpdateImageLayout(true)) + { + target.UpdateSelectionThumbs(true); + target.UpdateMaskArea(true); + } } } @@ -67,7 +71,11 @@ private static void OnCropShapeChanged( if (target.TryUpdateAspectRatio()) { - target.UpdateImageLayout(); + if (target.TryUpdateImageLayout()) + { + target.UpdateSelectionThumbs(); + target.UpdateMaskArea(); + } } target.UpdateMaskArea(); diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs index 88bffffb512..260ef1a0172 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs @@ -455,7 +455,12 @@ public bool TrySetCroppedRegion(Rect rect) } _currentCroppedRect = rect; - UpdateImageLayout(true); + if (TryUpdateImageLayout(true)) + { + UpdateSelectionThumbs(true); + UpdateMaskArea(true); + } + return true; } } From bc40536f6d89fd759c294f0854e8cfd0b57a9c3a Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Sep 2022 20:00:53 -0500 Subject: [PATCH 08/13] Removed extra call to UpdateMaskArea --- .../ImageCropper/ImageCropper.Events.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs index 5f659c0a7c5..b5acb70ee56 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs @@ -187,7 +187,6 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) if (TryUpdateImageLayout()) { UpdateSelectionThumbs(); - UpdateMaskArea(); } UpdateMaskArea(); From 5dc89580778ad5fd8fe65bde6d7befd7cc7e559f Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Sep 2022 20:05:08 -0500 Subject: [PATCH 09/13] Removed second extra call to UpdateMaskArea --- .../ImageCropper/ImageCropper.Events.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs index b5acb70ee56..64470d26af6 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs @@ -189,8 +189,6 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) UpdateSelectionThumbs(); } - UpdateMaskArea(); - if (TryUpdateAspectRatio()) { if (TryUpdateImageLayout()) From 6eee40a93066b12be2783267002ea1ab3da49776 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Sep 2022 20:07:55 -0500 Subject: [PATCH 10/13] Removed extra call to TryUpdateImageLayout --- .../ImageCropper/ImageCropper.Events.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs index 64470d26af6..cb0e4b1af39 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs @@ -191,11 +191,8 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) if (TryUpdateAspectRatio()) { - if (TryUpdateImageLayout()) - { - UpdateSelectionThumbs(); - UpdateMaskArea(); - } + UpdateSelectionThumbs(); + UpdateMaskArea(); } } } From eaea805d0abeb029d6f63254323530f5ad99b96e Mon Sep 17 00:00:00 2001 From: Arlo Date: Mon, 26 Sep 2022 11:26:24 -0500 Subject: [PATCH 11/13] Update Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs Co-authored-by: hhchaos --- .../ImageCropper/ImageCropper.Logic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs index d1a51837e6f..e323a331de7 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs @@ -527,7 +527,7 @@ private void UpdateMaskArea(bool animate = false) /// private bool TryUpdateAspectRatio() { - if (!(KeepAspectRatio && Source != null && IsValidRect(_restrictedSelectRect))) + if (KeepAspectRatio is false || Source is null || IsValidRect(_restrictedSelectRect) is false) { return false; } From 7c70926bd6be639a7034258e3c693cafa96cd676 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 26 Sep 2022 11:28:57 -0500 Subject: [PATCH 12/13] Removed unused using statement --- .../ImageCropper/ImageCropper.Logic.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs index d1a51837e6f..36b3b5a125c 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Net; using System.Numerics; using Windows.Foundation; using Windows.UI.Xaml; From 5b47d71d8c8d48d78bf30a71cd2561198e7db93e Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 26 Sep 2022 11:31:39 -0500 Subject: [PATCH 13/13] Removed extra call to UpdateMaskArea --- .../ImageCropper/ImageCropper.Properties.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs index d506753dfe5..97eaf0567b6 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs @@ -74,7 +74,6 @@ private static void OnCropShapeChanged( if (target.TryUpdateImageLayout()) { target.UpdateSelectionThumbs(); - target.UpdateMaskArea(); } }