Make rotation work again

This commit is contained in:
Julien Richard 2022-01-25 21:13:08 +01:00
commit b9e601b4ff
2 changed files with 31 additions and 1 deletions

View file

@ -1824,5 +1824,27 @@ namespace Greenshot.Base.Core
return bitmap; return bitmap;
} }
/// <summary>
/// Rotate the image
/// </summary>
/// <param name="image">Input image</param>
/// <param name="rotationAngle">Angle in degrees</param>
/// <returns>Rotated image</returns>
public static Image Rotate(this Image image, float rotationAngle)
{
var bitmap = new Bitmap(image.Width, image.Height);
using var gfx = Graphics.FromImage(bitmap);
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
gfx.TranslateTransform((float)bitmap.Width / 2, (float)bitmap.Height / 2);
gfx.RotateTransform(rotationAngle);
gfx.TranslateTransform(-(float)bitmap.Width / 2, -(float)bitmap.Height / 2);
gfx.DrawImage(image, new Point(0, 0));
return bitmap;
}
} }
} }

View file

@ -207,7 +207,15 @@ namespace Greenshot.Editor.Drawing
private Image ComputeBitmap(int iconSize) private Image ComputeBitmap(int iconSize)
{ {
return EmojiRenderer.GetBitmap(Emoji, iconSize); var image = EmojiRenderer.GetBitmap(Emoji, iconSize);
if (_rotationAngle != 0)
{
var newImage = image.Rotate(_rotationAngle);
image.Dispose();
return newImage;
}
return image;
} }
private void ResetCachedBitmap() private void ResetCachedBitmap()