mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 14:24:43 -07:00
Add bitmap cache
This commit is contained in:
parent
33dd2b7a27
commit
076a8d23bd
1 changed files with 32 additions and 5 deletions
|
@ -36,7 +36,6 @@ using Greenshot.Base.Interfaces.Drawing;
|
||||||
using Greenshot.Editor.Helpers;
|
using Greenshot.Editor.Helpers;
|
||||||
using Image = System.Drawing.Image;
|
using Image = System.Drawing.Image;
|
||||||
using Matrix = System.Drawing.Drawing2D.Matrix;
|
using Matrix = System.Drawing.Drawing2D.Matrix;
|
||||||
using Point = System.Drawing.Point;
|
|
||||||
using Size = System.Windows.Size;
|
using Size = System.Windows.Size;
|
||||||
|
|
||||||
namespace Greenshot.Editor.Drawing
|
namespace Greenshot.Editor.Drawing
|
||||||
|
@ -53,6 +52,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
|
|
||||||
[NonSerialized] private System.Windows.Controls.Image _image;
|
[NonSerialized] private System.Windows.Controls.Image _image;
|
||||||
[NonSerialized] private bool _justCreated = true;
|
[NonSerialized] private bool _justCreated = true;
|
||||||
|
[NonSerialized] private Image _cachedImage = null;
|
||||||
|
|
||||||
private string _emoji;
|
private string _emoji;
|
||||||
private int _rotationAngle;
|
private int _rotationAngle;
|
||||||
|
@ -148,11 +148,23 @@ namespace Greenshot.Editor.Drawing
|
||||||
PropertyChanged += OnPropertyChanged;
|
PropertyChanged += OnPropertyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
ResetCachedBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Transform(Matrix matrix)
|
public override void Transform(Matrix matrix)
|
||||||
{
|
{
|
||||||
_rotationAngle += CalculateAngle(matrix);
|
_rotationAngle += CalculateAngle(matrix);
|
||||||
_rotationAngle %= 360;
|
_rotationAngle %= 360;
|
||||||
|
|
||||||
|
ResetCachedBitmap();
|
||||||
|
|
||||||
base.Transform(matrix);
|
base.Transform(matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,12 +197,23 @@ namespace Greenshot.Editor.Drawing
|
||||||
var iconSize = Math.Min(rect.Width, rect.Height);
|
var iconSize = Math.Min(rect.Width, rect.Height);
|
||||||
if (iconSize > 0)
|
if (iconSize > 0)
|
||||||
{
|
{
|
||||||
using var bitmap = GetBitmap(iconSize);
|
if (_cachedImage == null)
|
||||||
graphics.DrawImage(bitmap, Bounds);
|
{
|
||||||
|
// First draw or cache was invalidated
|
||||||
|
_cachedImage = ComputeBitmap(iconSize);
|
||||||
|
}
|
||||||
|
else if (iconSize != _cachedImage.Width)
|
||||||
|
{
|
||||||
|
// The elements was resized => recompute
|
||||||
|
_cachedImage.Dispose();
|
||||||
|
_cachedImage = ComputeBitmap(iconSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
graphics.DrawImage(_cachedImage, Bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Image GetBitmap(int iconSize)
|
private Image ComputeBitmap(int iconSize)
|
||||||
{
|
{
|
||||||
_image.Measure(new Size(iconSize, iconSize));
|
_image.Measure(new Size(iconSize, iconSize));
|
||||||
_image.Arrange(new Rect(0, 0, iconSize, iconSize));
|
_image.Arrange(new Rect(0, 0, iconSize, iconSize));
|
||||||
|
@ -211,7 +234,11 @@ namespace Greenshot.Editor.Drawing
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResetCachedBitmap()
|
||||||
|
{
|
||||||
|
_cachedImage?.Dispose();
|
||||||
|
_cachedImage = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class PickerExtensions
|
internal static class PickerExtensions
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue