Groups | Blog | Home
all groups > dotnet drawing api > april 2006 >

dotnet drawing api : ugly drawn text to bitmap buffer


carry
4/5/2006 11:07:12 PM
Hi all

I'm drawing text and some other shapes on bitmap buffer. All objects
just in one pass, but the text looks fuzzy as it were painted more times
when bitmap is dropped on Graphics. I checked it with diagnostic output
and it's drawing method is called just once, same as on other shapes.
Shapes are nice and smooth as i'm using antialiasing but the text is
thick and grained. I think there has to be something wrong in drawing of
that bitmap, but I can't find out what the problem is.
Any ideas would be appreciated very much.
Martin

the code:

protected override void OnPaint(PaintEventArgs pe)
{
Graphics g = pe.Graphics;
g.SmoothingMode = smooth;

if (dragging)
{
// put still shapes on background
if (buffer != null)
{
g.DrawImageUnscaled(buffer, 0, 0); // "valid"
shapes are already painted on bitmap and don't need to be called for draw

foreach (Shape shape in _shapes)
if (shape.Invalid)
shape.Draw(g);
}
}
else
{
foreach (Shape shape in _shapes)
shape.Draw(g);
}
// base.OnPaint(pe);
}


And this is how buffer is made:

private void FlushShapesToBuffer()
{
buffer = new Bitmap(this.ClientSize.Width,
this.ClientSize.Height);
Graphics g = Graphics.FromImage(buffer);
g.SmoothingMode = smooth;
foreach (Shape shape in _shapes)
if (!shape.Invalid)
shape.Draw(g);
g.Dispose();
}

Bob Powell [MVP]
4/6/2006 1:26:24 PM
Try setting the TextRenderingHint.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



[quoted text, click to view]

carry
4/8/2006 12:00:00 AM
[quoted text, click to view]
Thank you Bob, and also for all your helpful tutorials and advices.
As you may found out, this code was not much different than the one on
your site.
I tried that TextRenderingHint, but text was little bit different on
bitmap. It didn't look very nice. Clearing the area with
Graphics.Clear(Color) solved the problem instead. But i still wonder,
AddThis Social Bookmark Button