如果我使用
OnPaintBackground
提供的Graphics
对象,使用TextRenderer.DrawText()
方法,我的文本看起来完美无缺。但如果我创建自己的Bitmap
并使用从自己的Bitmap
获得的Graphics
对象,则文本看起来非常糟糕。它看起来像是使用黑色对文本进行抗锯齿处理,而不是位图的背景颜色。我可以避免这个问题,如果我使用Graphics.DrawString()
方法,但这种方法具有可怕的字距问题。我该怎么做?如何让TextRenderer.DrawText()
方法在使用位图内容时正确地进行抗锯齿处理?
看起来非常糟糕:
Bitmap bmp = new Bitmap(100, 100, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.Red);
TextFormatFlags tf = TextFormatFlags.Left;
TextRenderer.DrawText(g, @"C:\Development\Testing\blag", font, clip, Color.White,
Color.Transparent, tf);
}
看起来不错,但我想把它渲染到位图上,而不是控件表面:
protected override void OnPaintBackground(PaintEventArgs e)
{
e.Graphics.Clear(Color.Red);
TextFormatFlags tf = TextFormatFlags.Left;
TextRenderer.DrawText(e.Graphics, @"C:\Development\Testing\blag", font, clip,
Color.White, Color.Transparent, tf);
}
有什么区别?
DrawString
在我的机器上速度更快。 - Roman Starkov