Picked some changes from 37c0b98, Try to dispose IDisposable objects more diligently

Branch_2.1.x
Nathan Crawford 2016-04-04 16:42:20 -04:00 zatwierdzone przez Nathan Crawford
rodzic 07e700a48d
commit e30b2e1a85
1 zmienionych plików z 59 dodań i 40 usunięć

Wyświetl plik

@ -244,6 +244,13 @@ namespace embroideryReader
tempImage = destImage;
}
// About to abandon the current DrawArea object, dispose it now
if(DrawArea != null)
{
DrawArea.Dispose();
DrawArea = null;
}
// Add transparency grid
if (settings.transparencyGridEnabled)
{
@ -268,10 +275,15 @@ namespace embroideryReader
}
g.DrawImage(tempImage, 0, 0);
// Done with tempImage
tempImage.Dispose();
tempImage = null;
}
}
else
{
// Keeping the object tempImage was pointing at, so don't dispose it
DrawArea = tempImage;
}
@ -511,10 +523,12 @@ namespace embroideryReader
{
float inchesPerMM = 0.03937007874015748031496062992126f;
e.Graphics.ScaleTransform((float)(e.PageSettings.PrinterResolution.X * inchesPerMM * 0.01f), (float)(e.PageSettings.PrinterResolution.Y * inchesPerMM * 0.01f));
Bitmap tempDrawArea = design.designToBitmap((float)settings.threadThickness, settings.filterStiches, settings.filterStitchesThreshold, e.PageSettings.PrinterResolution.X * inchesPerMM * 0.2f);
using (Bitmap tempDrawArea = design.designToBitmap((float)settings.threadThickness, settings.filterStiches, settings.filterStitchesThreshold, e.PageSettings.PrinterResolution.X * inchesPerMM * 0.2f))
{
e.Graphics.DrawImage(tempDrawArea, 30, 30);
}
}
}
private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -527,14 +541,17 @@ namespace embroideryReader
if (DrawArea != null)
{
Clipboard.Clear();
Bitmap temp = new Bitmap(DrawArea.Width, DrawArea.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics tempGraph = Graphics.FromImage(temp);
using (Bitmap temp = new Bitmap(DrawArea.Width, DrawArea.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
{
using (Graphics tempGraph = Graphics.FromImage(temp))
{
tempGraph.FillRectangle(Brushes.White, 0, 0, temp.Width, temp.Height);
tempGraph.DrawImageUnscaled(DrawArea, 0, 0);
tempGraph.Dispose();
}
Clipboard.SetImage(temp);
}
}
}
private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -587,12 +604,13 @@ namespace embroideryReader
{
if (DrawArea != null)
{
Bitmap temp = new Bitmap(DrawArea.Width, DrawArea.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics tempGraph = Graphics.FromImage(temp);
using (Bitmap temp = new Bitmap(DrawArea.Width, DrawArea.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
{
using (Graphics tempGraph = Graphics.FromImage(temp))
{
tempGraph.FillRectangle(Brushes.White, 0, 0, temp.Width, temp.Height);
tempGraph.DrawImageUnscaled(DrawArea, 0, 0);
tempGraph.Dispose();
}
saveFileDialog1.FileName = "";
// "Bitmap (*.bmp)|*.bmp|PNG (*.png)|*.png|JPEG (*.jpg)|*.jpg|GIF (*.gif)|*.gif|TIFF (*.tif)|*.tif|All Files (*.*)|*.*"
saveFileDialog1.Filter = translation.GetTranslatedString(Translation.StringID.FILE_TYPE_BMP) + " (*.bmp)|*.bmp|" +
@ -625,6 +643,7 @@ namespace embroideryReader
}
}
}
}
private void showStatus(string text, int msec)
{