Removed surface disposing, and making sure the PrintHelper itself is disposed correctly. Disposing the surface is not allowed in a destination, e.g. this would rip the surface away right from under the editor :)

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2503 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2013-02-20 09:16:28 +00:00
commit 0e86fa409c
2 changed files with 90 additions and 92 deletions

View file

@ -109,12 +109,18 @@ namespace Greenshot.Destinations {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
PrinterSettings printerSettings = null; PrinterSettings printerSettings = null;
if (!string.IsNullOrEmpty(printerName)) { if (!string.IsNullOrEmpty(printerName)) {
printerSettings = new PrintHelper(surface, captureDetails).PrintTo(printerName); using (PrintHelper printHelper = new PrintHelper(surface, captureDetails)) {
printerSettings = printHelper.PrintTo(printerName);
}
} else if (!manuallyInitiated) { } else if (!manuallyInitiated) {
PrinterSettings settings = new PrinterSettings(); PrinterSettings settings = new PrinterSettings();
printerSettings = new PrintHelper(surface, captureDetails).PrintTo(settings.PrinterName); using (PrintHelper printHelper = new PrintHelper(surface, captureDetails)) {
printerSettings = printHelper.PrintTo(settings.PrinterName);
}
} else { } else {
printerSettings = new PrintHelper(surface, captureDetails).PrintWithDialog(); using (PrintHelper printHelper = new PrintHelper(surface, captureDetails)) {
printerSettings = printHelper.PrintWithDialog();
}
} }
if (printerSettings != null) { if (printerSettings != null) {
exportInformation.ExportMade = true; exportInformation.ExportMade = true;

View file

@ -75,9 +75,6 @@ namespace Greenshot.Helpers {
*/ */
protected virtual void Dispose(bool disposing) { protected virtual void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (surface != null) {
surface.Dispose();
}
if (printDocument != null) { if (printDocument != null) {
printDocument.Dispose(); printDocument.Dispose();
} }
@ -111,8 +108,6 @@ namespace Greenshot.Helpers {
LOG.Error("An error ocurred while trying to print", e); LOG.Error("An error ocurred while trying to print", e);
MessageBox.Show(Language.GetString(LangKey.print_error), Language.GetString(LangKey.error)); MessageBox.Show(Language.GetString(LangKey.print_error), Language.GetString(LangKey.error));
} }
surface.Dispose();
surface = null;
return returnPrinterSettings; return returnPrinterSettings;
} }
@ -139,8 +134,6 @@ namespace Greenshot.Helpers {
} }
} }
surface.Dispose();
surface = null;
return returnPrinterSettings; return returnPrinterSettings;
} }
@ -171,7 +164,7 @@ namespace Greenshot.Helpers {
ApplyEffects(printOutputSettings); ApplyEffects(printOutputSettings);
Image image; Image image;
Boolean disposeImage = ImageOutput.CreateImageFromSurface(surface, printOutputSettings, out image); bool disposeImage = ImageOutput.CreateImageFromSurface(surface, printOutputSettings, out image);
try { try {
ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft; ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;
@ -238,8 +231,7 @@ namespace Greenshot.Helpers {
} }
} }
private void ApplyEffects(SurfaceOutputSettings printOutputSettings) private void ApplyEffects(SurfaceOutputSettings printOutputSettings) {
{
// TODO: // TODO:
// add effects here // add effects here
if (conf.OutputPrintMonochrome) { if (conf.OutputPrintMonochrome) {