mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Added scaling for the image container
This commit is contained in:
parent
621cc7fd0c
commit
52f56d7be5
2 changed files with 45 additions and 6 deletions
|
@ -47,6 +47,11 @@ namespace Greenshot.Drawing {
|
||||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(DrawableContainer));
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(DrawableContainer));
|
||||||
protected static readonly EditorConfiguration EditorConfig = IniConfig.GetIniSection<EditorConfiguration>();
|
protected static readonly EditorConfiguration EditorConfig = IniConfig.GetIniSection<EditorConfiguration>();
|
||||||
private bool _isMadeUndoable;
|
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;
|
protected EditStatus _defaultEditMode = EditStatus.DRAWING;
|
||||||
public EditStatus DefaultEditMode {
|
public EditStatus DefaultEditMode {
|
||||||
|
@ -692,6 +697,24 @@ namespace Greenshot.Drawing {
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the Y scale from the matrix
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matrix"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static float CalculateScaleY(Matrix matrix) {
|
||||||
|
return matrix.Elements[M22];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the X scale from the matrix
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matrix"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static float CalculateScaleX(Matrix matrix) {
|
||||||
|
return matrix.Elements[M11];
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve the rotation angle from the matrix
|
/// Retrieve the rotation angle from the matrix
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -145,14 +145,30 @@ namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matrix"></param>
|
/// <param name="matrix"></param>
|
||||||
public override void Transform(Matrix matrix) {
|
public override void Transform(Matrix matrix) {
|
||||||
base.Transform(matrix);
|
int rotateAngle = CalculateAngle(matrix);
|
||||||
LOG.DebugFormat("Rotating element with {0} degrees.", CalculateAngle(matrix));
|
// we currently assume only one transformation has been made.
|
||||||
|
if (rotateAngle != 0) {
|
||||||
|
LOG.DebugFormat("Rotating element with {0} degrees.", rotateAngle);
|
||||||
DisposeShadow();
|
DisposeShadow();
|
||||||
using (var tmpMatrix = new Matrix()) {
|
using (var tmpMatrix = new Matrix()) {
|
||||||
using (image) {
|
using (Image tmpImage = image) {
|
||||||
image = ImageHelper.ApplyEffect(image, new RotateEffect(CalculateAngle(matrix)), tmpMatrix);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue