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);
PrinterSettings printerSettings = null;
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) {
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 {
printerSettings = new PrintHelper(surface, captureDetails).PrintWithDialog();
using (PrintHelper printHelper = new PrintHelper(surface, captureDetails)) {
printerSettings = printHelper.PrintWithDialog();
}
}
if (printerSettings != null) {
exportInformation.ExportMade = true;

View file

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