-
March 5th, 2012, 02:03 AM
#1
[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...
Last edited by sean.aulason; March 5th, 2012 at 02:06 AM.
-
March 6th, 2012, 02:01 AM
#2
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
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.
-
March 6th, 2012, 02:03 AM
#3
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!
EDIT:
thanks a lot BioPhysEngr!
we posted at the same time. it works like a charm.
Last edited by sean.aulason; March 6th, 2012 at 02:08 AM.
-
March 6th, 2012, 02:03 AM
#4
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.
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.
-
March 6th, 2012, 02:10 AM
#5
Re: Drawn Text looks pixelated!
TextHint does the job for me. thank you again, BioPhysEngr...
-
March 6th, 2012, 02:19 AM
#6
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. :-)
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|