Question

When I draw a string into a buffer, the resulting output is not anti-aliased the way I'd expect. This code illustrates the problem... just put this in a standard smart device project's 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);
}

On the other hand, if I just draw the string into the Graphics object that was passed in with the PaintEventArgs, it renders in ClearType just as I'd expect.

I figure I've got to create my Graphics buffer in a way that makes it use font smoothing, but I don't see a way to do that.

Was it helpful?

Solution

Turns out to have been a simple problem. By removing the PixelFormat.Format32bppRgb it worked fine. Looks like you need to make sure your buffers have the same pixel formats...

OTHER TIPS

Set the SmoothingMode property of your Graphics object:

g.SmoothingMode = SmoothingMode.AntiAlias;

You will have to use gdiplus.dll (there exists a few wrappers for this), but it is only available on Windows Mobile 6 Professional (not Standard).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top