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...
Last edited by sean.aulason; March 5th, 2012 at 01:06 AM.
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.
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
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.
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Glad to help! The 2D graphics libraries are pretty powerful, but sometimes it takes a few tricks to make them work well. :-)
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Bookmarks