[RESOLVED] Drawn Text looks pixelated!
hi there,
the following code draws a text on the picture box, but it looks pixelated and seems bold, no matter what font-face and font-size i use and no matter i use FontStyle.Regular or not...
on the other hand, if i use any other color than black, the text will have a pixelated black outline as well!
Code:
System.Drawing.Font ft = new System.Drawing.Font("Verdana", 8.25f);
br = System.Drawing.Brushes.Black;
Bitmap bm = new Bitmap(picturebox1.Width, picturebox1.Height);
Graphics g = Graphics.FromImage(bm);
g.DrawString("My String", ft, br, 10, 10);
picturebox1.Image = bm;
ft.Dispose();
g.Dispose();
NOTE: since i'm drawing something else on the picture box, i'm using BITMAP to prevent the drawing to be cleared as soon as the control is refreshed...
Re: Drawn Text looks pixelated!
You need to give the Graphics object a hint how to render text:
Code:
Graphics g = //From somewhere
//Set this before rendering any text
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.DrawString(...); //Should look nice now
I think I've used this before with good results. Post again if it doesn't resolve the issue.
See the relevat MSDN link: http://msdn.microsoft.com/en-us/library/a619zh6z.aspx
Re: Drawn Text looks pixelated!
here is a snapshot of what i said about the text. as you see the text is jagged and seems bold!
http://img528.imageshack.us/img528/6320/capturewpc.png
EDIT:
thanks a lot BioPhysEngr!
we posted at the same time. it works like a charm.
Re: Drawn Text looks pixelated!
You can also do a form of anti-aliasing by rendering the image 2x or 4x larger than you want that final image to be and then scaling it down. As I recall, the downscaling algorithm in the System.Drawing namespace isn't very advanced (I don't think it does cubic or sync sampling or anything), so only use this option if you are using C# to output an image you will later manipulate in a dedicated image editor (e.g. Photoshop, GIMP, etc).
However, try the TextHint thing first. This option is not preferable.
Re: Drawn Text looks pixelated!
TextHint does the job for me. thank you again, BioPhysEngr...
Re: [RESOLVED] Drawn Text looks pixelated!
Glad to help! The 2D graphics libraries are pretty powerful, but sometimes it takes a few tricks to make them work well. :-)