2

当我将字符串绘制到缓冲区中时,生成的输出不会像我期望的那样抗锯齿。这段代码说明了问题......只需将其放入标准智能设备项目的 Form1.cs 中:

protected override void OnPaint(PaintEventArgs e)
{
  Bitmap buffer = new Bitmap(Width, Height, PixelFormat.Format32bppRgb);
  using(Graphics g = Graphics.FromImage(buffer))
  {
    g.Clear(Color.White);
    g.DrawString("Hello, World", Font, new SolidBrush(Color.Black), 5, 5);
  }
  e.Graphics.DrawImage(buffer, 0, 0);
}

另一方面,如果我只是将字符串绘制到使用 传入的 Graphics 对象中PaintEventArgs,它会按照我的预期呈现在 ClearType 中。

我想我必须以一种使其使用字体平滑的方式创建我的图形缓冲区,但我看不到这样做的方法。

4

3 回答 3

3

原来是一个简单的问题。通过删除PixelFormat.Format32bppRgb它工作正常。看起来您需要确保缓冲区具有相同的像素格式...

于 2009-07-27T21:51:37.033 回答
0

设置 Graphics 对象的 SmoothingMode 属性:

g.SmoothingMode = SmoothingMode.AntiAlias;
于 2009-07-27T12:42:17.893 回答
0

您将不得不使用 gdiplus.dll(为此存在一些包装器),但它仅适用于 Windows Mobile 6 Professional(非标准版)。

于 2009-07-27T12:44:13.757 回答