views:

170

answers:

2

I'm writing a printing routing in C#, using the .NET PrintDocument class, handling the OnPrintPage event.

I've managed to maximize the margins and print the Image in landscape mode, but it simply does not look as good as when I print the same image file from Windows Photo Gallery (formerly Windows Picture and Fax Viewer), the default image preview program in Windows Vista.

I noticed an option there for selecting "Sharpen Image for Printing", but what does that do?

I've thought about printing copies of the image from Windows Photo Gallery first, then sending the sheets through the printer a second time to print the custom overlays I need, but it's hard to make it line up every time, since the printer sucks the sheet in without the kind of precision I need... so I really need to do ALL the drawing commands within C#, including the image.

Does anyone know how to perform pre-processing on the bitmap so that it prints as nicely as Windows Photo Gallery does it? Are there any simple print drivers that can intercept Photo Gallery printing output as a standard image file (bmp, png, etc.) that can be read by the .NET Image class? I'm all for creativity here.

A: 

If you're trying to take a small image and print a large version of it, it might help to create a larger version of your image in memory and then print that larger version. This is generally how you would do this:

Bitmap largeBitmap = new Bitmap(800, 600);
using (Graphics g = Graphics.FromImage(largeBitmap))
{
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g.DrawImage(smallImage ...) // I forget which of the 30 
        // overloads you need here
}
// then print largeBitmap

Basically you'd be letting GDI+ resize the image instead of the printer; this may or may not be an improvement. The "sharpening" in Photo Gallery is certainly more sophisticated than this, and targeted at printing issues.

MusiGenesis
I don't think the higher quality has much to do with the interprolation in this particular case, although I will try that out, since there IS some scaling involved. It really seems to be doing something with the colors, as I notice there are no "bands" in the shadows printed from Windows Photo Gallery like there are when I print it from C# unmodified.
Triynko
+1  A: 

Paint.Net uses the Windows Picture and Fax Viewer for its printing and it was previously open source.

A quick Google for "Paint.Net source" seems to turn it up, albeit in earlier incarnations before they closed it again. I'd look at their source and see how they invoke the dialog

Rob Cowell