我将尝试使用TextRenderer(因为这比使用Graphics.DrawString更好)在Bitmap上绘制一些文本,但是它会产生一些非常不良的效果。
示例代码
using (Bitmap buffer = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using (Graphics graphics = Graphics.FromImage(buffer))
{
// Produces the result below
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
// Produces clean text, but I'd really like ClearType!
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
TextRenderer.DrawText(graphics, "Hello World", this.Font, this.ClientRectangle, Color.Black);
}
e.Graphics.DrawImageUnscaled(buffer, this.ClientRectangle);
}
结果
我不确定如何解决这个问题...请帮忙!
我不想使用Graphics.DrawString
,因为我想要正确的GDI(而不是GDI+)渲染。
注意:我刚意识到,我在这个问题中留下了一个巨大的漏洞。有些人指出,在他们的计算机上渲染ClearType文本没有问题...
我试图将文本渲染到透明(Color.Transparent)位图上。如果我用纯色来做,一切都正常!(但是我必须渲染到透明的位图上)。
Graphics.InterpolationMode
和Graphics.SmoothingMode
。 - Hamlet Hakobyan