Asked by:
drawing text on graphics

Question
-
User-577991800 posted
I know how to draw text on graphics and all thats fine however I do have a couple of questions
1) the text comes out blurry on jpg images. Any ideas on how to make it clearer and smooth?
2) what font can you recommend that I can use which looks good, the font color I will be using is white since the images are generally dark. I just can't seem to find a font I am attracted to.
Thanks!
Saturday, May 3, 2008 7:57 PM
All replies
-
User68971474 posted
When I see blurry text in a graphic sometimes it's because image is not displayed at exact image size.
For example, if image size is 100 x 100, but you display it as 105 x 105, text will blur.
HTH
Monday, May 5, 2008 2:52 AM -
User-577991800 posted
well not quite. The image is fine, crystal clear... but when adding text, the text is the only thing that is blurry.
Monday, May 5, 2008 4:59 AM -
User-1585994330 posted
if you mean watermarking an image with text have a look at :
http://www.codeproject.com/KB/GDI-plus/watermark.aspx
really helped me with my watermark issues, Si!Monday, May 5, 2008 9:13 AM -
User-577991800 posted
Thanks but I don't mean watermarking :)
Monday, May 5, 2008 9:19 AM -
User68971474 posted
when adding text, the text is the only thing that is blurryWe better look at your code...
Monday, May 5, 2008 7:49 PM -
User-577991800 posted
using (Image b = Bitmap.FromFile(images[randomNumber])){
using (Graphics g = Graphics.FromImage(b)){
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;g.DrawString("Because I had to!", new Font("Comic Sans MS", 30, FontStyle.Bold), Brushes.White, new PointF(290, 10));b.Dispose();
g.Dispose();
}
}
Monday, May 5, 2008 7:55 PM -
User68971474 posted
I don't see anything unusual in this code. Could you email a copy of your graphic with blurry text?
Monday, May 5, 2008 8:20 PM -
User68971474 posted
Hi Ahmed,I opened MS Word and created your text using the same font. Word produces identical text to that in your image. So I don't think the text in your graphic is blurry; it's perfectly rendered.Comic Sans MS appears to have a certain jagged quality designed into it.The only suggestion I have is experiment with some kind of colored outline or border on the text. It might soften the boundaries between your white text and its dark background.For smoother boundaries I think you'd have to turn to a different graphics tool. But I don't have any suggestions for better alternatives.HTHGood luck!RickMonday, May 5, 2008 9:45 PM -
User68971474 posted
Ahmed,
You could also reduce jaggedness of a font by reducing its size. However, I realize such action can reduce the readability of the text, too.
Rick
Monday, May 5, 2008 9:58 PM -
User-1382472478 posted
Hello GeoSync,
Can you post an example how you can "outline" and "border" text, when you using DrawString.
Thanx.
Monday, May 26, 2008 4:39 PM -
User1619112118 posted
To outline a string, create a graphicspath and use addstring. use this graphicspath in a region and it wil display as an outline of the text
Monday, June 16, 2008 11:43 PM -
Sunday, January 18, 2009 1:40 AM
-
User1619112118 posted
Imports System.Drawing Imports System.Drawing.Drawing2D Dim b As New Bitmap(500, 400) Dim g As Graphics Dim gp As New GraphicsPath gp.AddString("Test String", FontFamily.GenericSerif, 0, 72, New PointF(100, 250), New StringFormat) g = Graphics.FromImage(b) g.Clear(Color.White) g.SmoothingMode = SmoothingMode.HighQuality g.DrawPath(Pens.Black, gp) Response.AddHeader("Content-Type", "binary/octet-stream") Response.AddHeader("Content-Disposition", "filename=img.jpg") Response.Flush() b.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
the g.SmoothingMode sets the smoothness, obviously, of the GraphicsPath.
the graininess or blurriness usually comes up on these GDI images so dont worry too much about it.
Monday, January 19, 2009 7:57 PM -
User1047346766 posted
I was having a similar issue - but I switched to GIF output format and it's fine now.
Monday, June 29, 2009 9:35 AM