diff --git a/Greenshot/Drawing/Filters/BlurFilter.cs b/Greenshot/Drawing/Filters/BlurFilter.cs index 63f62b2bb..44457603e 100644 --- a/Greenshot/Drawing/Filters/BlurFilter.cs +++ b/Greenshot/Drawing/Filters/BlurFilter.cs @@ -45,7 +45,6 @@ namespace Greenshot.Drawing.Filters { public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS); - double previewQuality = GetFieldValueAsDouble(FieldType.PREVIEW_QUALITY); Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { return; diff --git a/Greenshot/Drawing/Filters/BrightnessFilter.cs b/Greenshot/Drawing/Filters/BrightnessFilter.cs index 17f9615e3..b9dccb79c 100644 --- a/Greenshot/Drawing/Filters/BrightnessFilter.cs +++ b/Greenshot/Drawing/Filters/BrightnessFilter.cs @@ -55,8 +55,9 @@ namespace Greenshot.Drawing.Filters { graphics.ExcludeClip(rect); } float brightness = GetFieldValueAsFloat(FieldType.BRIGHTNESS); - ImageAttributes ia = ImageHelper.CreateAdjustAttributes(brightness, 1f, 1f); - graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia); + using (ImageAttributes ia = ImageHelper.CreateAdjustAttributes(brightness, 1f, 1f)) { + graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia); + } graphics.Restore(state); } } diff --git a/Greenshot/Drawing/Filters/GrayscaleFilter.cs b/Greenshot/Drawing/Filters/GrayscaleFilter.cs index 3478977fe..c359c04f8 100644 --- a/Greenshot/Drawing/Filters/GrayscaleFilter.cs +++ b/Greenshot/Drawing/Filters/GrayscaleFilter.cs @@ -53,9 +53,10 @@ namespace Greenshot.Drawing.Filters { new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }); - ImageAttributes ia = new ImageAttributes(); - ia.SetColorMatrix(grayscaleMatrix); - graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia); + using (ImageAttributes ia = new ImageAttributes()) { + ia.SetColorMatrix(grayscaleMatrix); + graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia); + } graphics.Restore(state); } diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index 2fca366f4..d85b71f8f 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -688,6 +688,9 @@ namespace Greenshot.Forms { // Horizontal middle + 1 to right graphics.DrawRectangle(pen, destinationRectangle.X + halfWidthEnd + 2 * padding, drawAtHeight, halfWidthEnd - 2 * padding - 1, pixelThickness); } + if (attributes != null) { + attributes.Dispose(); + } } /// diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 8b37804c5..c2f07ae73 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -904,10 +904,11 @@ namespace GreenshotPlugin.Core { /// Image to copy to /// ColorMatrix to apply public static void ApplyColorMatrix(Bitmap source, Rectangle sourceRect, Bitmap dest, Rectangle destRect, ColorMatrix colorMatrix) { - ImageAttributes imageAttributes = new ImageAttributes(); - imageAttributes.ClearColorMatrix(); - imageAttributes.SetColorMatrix(colorMatrix); - ApplyImageAttributes(source, sourceRect, dest, destRect, imageAttributes); + using (ImageAttributes imageAttributes = new ImageAttributes()) { + imageAttributes.ClearColorMatrix(); + imageAttributes.SetColorMatrix(colorMatrix); + ApplyImageAttributes(source, sourceRect, dest, destRect, imageAttributes); + } } /// @@ -1049,7 +1050,9 @@ namespace GreenshotPlugin.Core { //create a blank bitmap the same size as original // If using 8bpp than the following exception comes: A Graphics object cannot be created from an image that has an indexed pixel format. Bitmap newBitmap = CreateEmpty(sourceImage.Width, sourceImage.Height, PixelFormat.Format24bppRgb, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution); - ApplyImageAttributes((Bitmap)sourceImage, Rectangle.Empty, newBitmap, Rectangle.Empty, CreateAdjustAttributes(brightness, contrast, gamma)); + using (ImageAttributes adjustAttributes = CreateAdjustAttributes(brightness, contrast, gamma)) { + ApplyImageAttributes((Bitmap)sourceImage, Rectangle.Empty, newBitmap, Rectangle.Empty, adjustAttributes); + } return newBitmap; } @@ -1404,7 +1407,10 @@ namespace GreenshotPlugin.Core { using (Graphics graphics = Graphics.FromImage(newImage)) { graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; - graphics.DrawImage(sourceImage, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), GraphicsUnit.Pixel); + using (ImageAttributes wrapMode = new ImageAttributes()) { + wrapMode.SetWrapMode(WrapMode.TileFlipXY); + graphics.DrawImage(sourceImage, new Rectangle(destX, destY, destWidth, destHeight), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, wrapMode); + } } return newImage; }