mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Fixed issue where a bitmap was not disposed, causing a memory leak if there were more than 256 colors on the image and it was not forcefully quantized.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2455 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
5a1c8ffefb
commit
7ba6a57b4a
2 changed files with 34 additions and 18 deletions
|
@ -259,7 +259,7 @@ namespace GreenshotPlugin.Core {
|
|||
|
||||
// check for color reduction, forced or automatically, only when the DisableReduceColors is false
|
||||
if (!outputSettings.DisableReduceColors && (conf.OutputFileAutoReduceColors || outputSettings.ReduceColors)) {
|
||||
WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave);
|
||||
using (WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave)) {
|
||||
int colorCount = quantizer.GetColorCount();
|
||||
LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
|
||||
if (outputSettings.ReduceColors || colorCount < 256) {
|
||||
|
@ -278,6 +278,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return disposeImage;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace GreenshotPlugin.Core {
|
|||
public Int32 Volume { get; set; }
|
||||
}
|
||||
|
||||
public class WuQuantizer {
|
||||
public class WuQuantizer : IDisposable {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WuQuantizer));
|
||||
|
||||
private const Int32 MAXCOLOR = 512;
|
||||
|
@ -100,6 +100,13 @@ namespace GreenshotPlugin.Core {
|
|||
private Bitmap sourceBitmap;
|
||||
private Bitmap resultBitmap;
|
||||
|
||||
public void Dispose() {
|
||||
if (resultBitmap != null) {
|
||||
resultBitmap.Dispose();
|
||||
resultBitmap = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See <see cref="IColorQuantizer.Prepare"/> for more details.
|
||||
/// </summary>
|
||||
|
@ -222,7 +229,11 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
}
|
||||
resultBitmap.Palette = imagePalette;
|
||||
return resultBitmap;
|
||||
|
||||
// Make sure the bitmap is not disposed, as we return it.
|
||||
Bitmap tmpBitmap = resultBitmap;
|
||||
resultBitmap = null;
|
||||
return tmpBitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -361,7 +372,11 @@ namespace GreenshotPlugin.Core {
|
|||
imagePalette.Entries[paletteIndex] = Color.FromArgb(255, reds[paletteIndex], greens[paletteIndex], blues[paletteIndex]);
|
||||
}
|
||||
resultBitmap.Palette = imagePalette;
|
||||
return resultBitmap;
|
||||
|
||||
// Make sure the bitmap is not disposed, as we return it.
|
||||
Bitmap tmpBitmap = resultBitmap;
|
||||
resultBitmap = null;
|
||||
return tmpBitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue