views:

356

answers:

3

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.

A: 

Set the SmoothingMode property of your Graphics object:

g.SmoothingMode = SmoothingMode.AntiAlias;
MusiGenesis
I somehow doubt this is available on CF.
leppie
You're right - it's not there.
MusiGenesis
A: 

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).

leppie
+3  A: 

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...

Hugh

related questions