diff --git a/Greenshot/Destinations/PrinterDestination.cs b/Greenshot/Destinations/PrinterDestination.cs index e1ce2f0c4..bf4a394c0 100644 --- a/Greenshot/Destinations/PrinterDestination.cs +++ b/Greenshot/Destinations/PrinterDestination.cs @@ -30,6 +30,7 @@ using GreenshotPlugin.Core; using Greenshot.Plugin; using Greenshot.Helpers; using Greenshot.IniFile; +using Greenshot.Core; namespace Greenshot.Destinations { /// @@ -87,27 +88,55 @@ namespace Greenshot.Destinations { } } + /// + /// Create destinations for all the installed printers + /// + /// IEnumerable public override IEnumerable DynamicDestinations() { foreach (string printer in PrinterSettings.InstalledPrinters) { yield return new PrinterDestination(printer); } } + /// + /// Export the capture to the printer + /// + /// + /// + /// + /// ExportInformation public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); PrinterSettings printerSettings = null; - using (Image image = surface.GetImageForExport()) { + + // Create the output settins + SurfaceOutputSettings printOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false); + + // TODO: + // add effects here, e.g. Monochrome + // printOutputSettings.Effects.Add(new MonochromeEffect()); + // Set the color reducing if needed, this should change the 24/32-> 8 (or later even 1) bpp + // printOutputSettings.ReduceColors = true; + + Image imageToPrint; + Boolean disposeImage = ImageOutput.CreateImageFromSurface(surface, printOutputSettings, out imageToPrint); + try { if (!string.IsNullOrEmpty(printerName)) { - printerSettings = new PrintHelper(image, captureDetails).PrintTo(printerName); + printerSettings = new PrintHelper(imageToPrint, captureDetails).PrintTo(printerName); } else if (!manuallyInitiated) { PrinterSettings settings = new PrinterSettings(); - printerSettings = new PrintHelper(image, captureDetails).PrintTo(settings.PrinterName); + printerSettings = new PrintHelper(imageToPrint, captureDetails).PrintTo(settings.PrinterName); } else { - printerSettings = new PrintHelper(image, captureDetails).PrintWithDialog(); + printerSettings = new PrintHelper(imageToPrint, captureDetails).PrintWithDialog(); } if (printerSettings != null) { exportInformation.ExportMade = true; } + } finally { + if (disposeImage && imageToPrint != null) { + imageToPrint.Dispose(); + imageToPrint = null; + } } ProcessExport(exportInformation, surface); diff --git a/GreenshotPlugin/Core/Effects.cs b/GreenshotPlugin/Core/Effects.cs index a5ad4df7a..dcbaf9ff0 100644 --- a/GreenshotPlugin/Core/Effects.cs +++ b/GreenshotPlugin/Core/Effects.cs @@ -101,6 +101,16 @@ namespace Greenshot.Core { } } + /// + /// MonochromeEffect + /// + public class MonochromeEffect : IEffect { + public Image Apply(Image sourceImage, out Point offsetChange) { + offsetChange = Point.Empty; + return ImageHelper.CreateMonochrome(sourceImage); + } + } + /// /// InvertEffect ///