用C#打印图像,颜色比从OS打印更不透明

时间:2013-09-03 19:23:10

标签: c# .net printing gdi+ system.drawing

我正在尝试从winforms应用程序打印JPG图像,我需要颜色非常接近原始图像,但是生成的颜色与使用OS打印的图像(从Windows照片查看器)相比更加不透明或者单词)。

这是代码:

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();
        }
    }

我尝试使用不同的图形属性值(SmoothingMode,PixelOffsetMode,...),但我无法获得真实的颜色。例如,当应用程序打印时,黑色更像是灰色,但是用单词打印的内容非常接近黑色。

我无法发送完整的照片,但这是具有相同属性的JPG部分:

enter image description here

0 个答案:

没有答案