在其上绘制文字时图像质量低(C#)

时间:2012-05-31 05:07:32

标签: c# image image-processing

我要创建一个位图图像并绘制文本但是用于打印目的的图像质量很低,像素是可见的,而不像我通过微软词打印时那样。

我不想使用PrintDocument。

Anti Aliasing也没有帮助我,我尝试过所有图像类型(Tif,bmp,png)

以下是我们使用的代码的一部分。

MyBitmap = new System.Drawing.Bitmap(GetMaxWidthOfReport(), MyActualPageSizeInfo.Height);

Mygraphics =System.Drawing.Graphics.FromImage(MyBitmap);

Mygraphics.TextContrast = 4;
Mygraphics.PageUnit = System.Drawing.GraphicsUnit.Display; 
Mygraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 
Mygraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; 
Mygraphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; 
Mygraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
Mygraphics.InterpolationMode =     System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; 

Mygraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

如果您有任何解决方案,请与我们联系。

1 个答案:

答案 0 :(得分:4)

请尝试以下方法:

var bmp = new Bitmap(300, 100, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using(Graphics g = Graphics.FromImage(bmp)) {
    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
    System.Windows.Forms.TextRenderer.DrawText(g, 
        @"low image quality when draw text on it", Font, new Point(10, 10), Color.Black);
}