Skip to main content
 首页 » 编程设计

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

2024年02月20日11lori

我要创建位图图像并绘制文本,但用于打印目的的图像质量很低,像素可见,不像我通过 Microsoft Word 打印时那样。

出于某些原因我不想使用 PrintDocument。

抗锯齿对我也没有帮助,我已经尝试了所有图像类型(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; 

如果您有任何解决方案,请告诉我。

请您参考如下方法:

请尝试以下方法:

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