Printing visual images in black and white

How can I print a visual grayscale image without actually displaying the PrintDialog like

PrintDialog dialog = new Dialog();
dialog.PrintQueue = new PrintQueue(new PrintServer(), printerNameAsString);
dialog.PrintTicket.InputBin = InputBin.AutoSelect;
// Further settings, e.g. PageMediaSize and scaling the visual.    

dialog.PrintVisual(myVisual, "myDescription");

      

Is there any way I can get PrinterDialog to print visuals in grayscale? Or is there a completely different way to achieve grayscale printing of my visual?

Edit: myVisual (Visual I want to print) is a Grid, so it inherits from UIElement. Edit 2: If possible, I would rather not use external libraries (due to company policy).

+3


source to share


3 answers


In PrintDialog, you can set the OutputColor:

myPrintDialog.PrintTicket.OutputColor = OutputColor.Grayscale;

      

In addition, PrintCapabilities allows you to actually check which OutputColors are possible:



PrintCapabilities capabilities = myPrintDialog.PrintQueue.GetPrintCapabilities(myPrintDialog.PrintTicket);
ReadOnlyCollection<OutputColor> possibleColors = capabilities.OutputColorCapability;

      

On the hardware available to me, this works great.

+2


source


You can try using the standard lib build in Microsoft.Expression.Effects

. The effect is here MonochromeEffect

. Just apply this effect before printing your image:

myVisual.Effect = new MonochromeEffect();//make grayscale
dialog.PrintVisual(myVisual, "myDescription");
myVisual.Effect = null; //turn it off

      



You need to import the library mentioned above and add it using the instruction:

using Microsoft.Expression.Media.Effects;

      

+1


source


I ran into a similar issue where the DrawString always printed solid black - even though the brushes specified a lighter shade. Finally, I found that by placing the image on the artwork, it would print the lighter shades that were in the image. This looks like a hack, but it works! (Maybe the printdialog solution worked too - I don't know, since I am printing automatically from a service where there is no printdialog.)

0


source







All Articles