diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs index 32d5bb923..b1d4be4c3 100644 --- a/Greenshot/Drawing/DrawableContainer.cs +++ b/Greenshot/Drawing/DrawableContainer.cs @@ -47,6 +47,11 @@ namespace Greenshot.Drawing { private static readonly ILog LOG = LogManager.GetLogger(typeof(DrawableContainer)); protected static readonly EditorConfiguration EditorConfig = IniConfig.GetIniSection(); private bool _isMadeUndoable; + private const int M11 = 0; + private const int M12 = 1; + private const int M21 = 2; + private const int M22 = 3; + protected EditStatus _defaultEditMode = EditStatus.DRAWING; public EditStatus DefaultEditMode { @@ -692,6 +697,24 @@ namespace Greenshot.Drawing { Invalidate(); } + /// + /// Retrieve the Y scale from the matrix + /// + /// + /// + public static float CalculateScaleY(Matrix matrix) { + return matrix.Elements[M22]; + } + + /// + /// Retrieve the X scale from the matrix + /// + /// + /// + public static float CalculateScaleX(Matrix matrix) { + return matrix.Elements[M11]; + } + /// /// Retrieve the rotation angle from the matrix /// diff --git a/Greenshot/Drawing/ImageContainer.cs b/Greenshot/Drawing/ImageContainer.cs index 4bb992808..6f2267f67 100644 --- a/Greenshot/Drawing/ImageContainer.cs +++ b/Greenshot/Drawing/ImageContainer.cs @@ -145,14 +145,30 @@ namespace Greenshot.Drawing { /// /// public override void Transform(Matrix matrix) { - base.Transform(matrix); - LOG.DebugFormat("Rotating element with {0} degrees.", CalculateAngle(matrix)); - DisposeShadow(); - using (var tmpMatrix = new Matrix()) { - using (image) { - image = ImageHelper.ApplyEffect(image, new RotateEffect(CalculateAngle(matrix)), tmpMatrix); + int rotateAngle = CalculateAngle(matrix); + // we currently assume only one transformation has been made. + if (rotateAngle != 0) { + LOG.DebugFormat("Rotating element with {0} degrees.", rotateAngle); + DisposeShadow(); + using (var tmpMatrix = new Matrix()) { + using (Image tmpImage = image) { + image = ImageHelper.ApplyEffect(image, new RotateEffect(rotateAngle), tmpMatrix); + } + } + } else { + float scaleX = CalculateScaleX(matrix); + float scaleY = CalculateScaleY(matrix); + int newWidth = (int)(Width * scaleX); + int newHeight = (int)(Height * scaleY); + if (newWidth != Width || newHeight != Height) { + using (var tmpMatrix = new Matrix()) { + using (Image tmpImage = image) { + image = ImageHelper.ApplyEffect(image, new ResizeEffect(newWidth, newHeight, false), tmpMatrix); + } + } } } + base.Transform(matrix); } ///