Tuesday, 3 September 2013

Printing Image in C#, colors more opaque than printing from OS

Printing Image in C#, colors more opaque than printing from OS

I'm trying to print a JPG image from a winforms application, I need the
colors to be really close to the original image but the resulting colors
are more opaque comparing them to the image printed with the OS (from
windows photo viewer or word).
This is the code:
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Pixel;
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
e.Graphics.PixelOffsetMode =
System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
e.Graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
//e.Graphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
e.Graphics.CompositingQuality =
System.Drawing.Drawing2D.CompositingQuality.GammaCorrected;
e.Graphics.CompositingMode =
System.Drawing.Drawing2D.CompositingMode.SourceCopy;
var img = Image.FromFile(@"C:\photo.jpg", true);
e.Graphics.DrawImage(img, 0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
var result = printDialog1.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
printDocument1.PrinterSettings = printDialog1.PrinterSettings;
printDocument1.Print();
}
}
I've tried with different values for the graphics properties
(SmoothingMode, PixelOffsetMode, ...) but I cannot get the real colors.
For example black is more like grey when printed by the application, but
printed with word is really close to black.
I cannot send the complete photo, but this is a section of the JPG with
the same properties:

No comments:

Post a Comment