This commit is contained in:
Julien Richard 2022-01-17 09:52:06 +01:00
commit fde1539ac5
2 changed files with 30 additions and 65 deletions

View file

@ -1804,29 +1804,6 @@ namespace Greenshot.Base.Core
return returnImage; return returnImage;
} }
/// <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;
}
/// <summary> /// <summary>
/// Returns a bitmap from a WPF bitmap source /// Returns a bitmap from a WPF bitmap source
/// </summary> /// </summary>

View file

@ -50,7 +50,6 @@ namespace Greenshot.Editor.Drawing
[NonSerialized] private static ElementHost _emojiPickerHost; [NonSerialized] private static ElementHost _emojiPickerHost;
[NonSerialized] private static Picker _emojiPicker; [NonSerialized] private static Picker _emojiPicker;
[NonSerialized] private System.Windows.Controls.Image _image;
[NonSerialized] private bool _justCreated = true; [NonSerialized] private bool _justCreated = true;
[NonSerialized] private Image _cachedImage = null; [NonSerialized] private Image _cachedImage = null;
@ -63,10 +62,7 @@ namespace Greenshot.Editor.Drawing
set set
{ {
_emoji = value; _emoji = value;
if (_image != null) ResetCachedBitmap();
{
global::Emoji.Wpf.Image.SetSource(_image, Emoji);
}
} }
} }
@ -141,10 +137,6 @@ namespace Greenshot.Editor.Drawing
{ {
CreateDefaultAdorners(); CreateDefaultAdorners();
// Create WPF control that will be used to render the emoji
_image = new System.Windows.Controls.Image();
global::Emoji.Wpf.Image.SetSource(_image, Emoji);
PropertyChanged += OnPropertyChanged; PropertyChanged += OnPropertyChanged;
} }
@ -215,23 +207,19 @@ namespace Greenshot.Editor.Drawing
private Image ComputeBitmap(int iconSize) private Image ComputeBitmap(int iconSize)
{ {
_image.Measure(new Size(iconSize, iconSize)); // Create WPF control that will be used to render the emoji
_image.Arrange(new Rect(0, 0, iconSize, iconSize)); var image = new System.Windows.Controls.Image();
global::Emoji.Wpf.Image.SetSource(image, Emoji);
image.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
image.RenderTransform = new RotateTransform(_rotationAngle);
image.Measure(new Size(iconSize, iconSize));
image.Arrange(new Rect(0, 0, iconSize, iconSize));
var renderTargetBitmap = new RenderTargetBitmap(iconSize, iconSize, 96, 96, PixelFormats.Pbgra32); var renderTargetBitmap = new RenderTargetBitmap(iconSize, iconSize, 96, 96, PixelFormats.Pbgra32);
renderTargetBitmap.Render(_image); renderTargetBitmap.Render(image);
var bitmap = renderTargetBitmap.ToBitmap(); return renderTargetBitmap.ToBitmap();
if (_rotationAngle != 0)
{
var newBitmap = bitmap.Rotate( _rotationAngle);
bitmap.Dispose();
return newBitmap;
}
return bitmap;
} }
private void ResetCachedBitmap() private void ResetCachedBitmap()