如果我使用我的文本中提供TextRenderer.DrawText()
的Graphics
对象OnPaintBackground
看起来很完美。如果我创建自己的Bitmap
并使用Graphics
从我Bitmap
的文本中获得的对象看起来很糟糕。看起来它是使用黑色而不是位图的背景颜色对文本进行抗锯齿处理。如果我使用 ,我可以避免这个问题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);
}
有什么不同?