ser*_*0ne 5 c# gdi+ gdi bitmap text-rendering
我正在尝试使用绘制一些文本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);
}
Run Code Online (Sandbox Code Playgroud)
结果

我不确定该如何解决...帮助!
我不想使用,Graphics.DrawString因为我想要正确的GDI(而不是GDI +)渲染。
注意:我刚刚意识到,我在这个问题上留下了一个空白。有人指出,呈现ClearType文本在他们的机器上可以正常工作...
我正在尝试将文本呈现为透明(Color.Transparent)位图。如果我用纯色做,一切正常!(但是我必须渲染为透明的位图)。
在调用 DrawText() 时指定 BackColor:
TextRenderer.DrawText(graphics, "Hello World", this.Font, this.ClientRectangle, Color.Black, this.BackColor);
Run Code Online (Sandbox Code Playgroud)