drawing text on graphics

Last post 06-29-2009 9:35 AM by aschaible. 14 replies.

Sort Posts:

  • drawing text on graphics

    05-03-2008, 7:57 PM
    • Member
      232 point Member
    • ahmedilyas
    • Member since 04-15-2006, 1:52 AM
    • UK
    • Posts 313

    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!

    C# MVP
  • Re: drawing text on graphics

    05-05-2008, 2:52 AM
    • Contributor
      2,349 point Contributor
    • geosync
    • Member since 03-26-2006, 8:44 PM
    • Boston, MA, USA
    • Posts 741

    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

    ~ Timing is Everything! ~
  • Re: drawing text on graphics

    05-05-2008, 4:59 AM
    • Member
      232 point Member
    • ahmedilyas
    • Member since 04-15-2006, 1:52 AM
    • UK
    • Posts 313

    well not quite. The image is fine, crystal clear... but when adding text, the text is the only thing that is blurry.

    C# MVP
  • Re: drawing text on graphics

    05-05-2008, 9:13 AM
    • Member
      197 point Member
    • blink18jew
    • Member since 05-22-2007, 12:12 AM
    • Posts 626
    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!
  • Re: drawing text on graphics

    05-05-2008, 9:19 AM
    • Member
      232 point Member
    • ahmedilyas
    • Member since 04-15-2006, 1:52 AM
    • UK
    • Posts 313

    Thanks but I don't mean watermarking :)

    C# MVP
  • Re: drawing text on graphics

    05-05-2008, 7:49 PM
    • Contributor
      2,349 point Contributor
    • geosync
    • Member since 03-26-2006, 8:44 PM
    • Boston, MA, USA
    • Posts 741

    ahmedilyas:
    when adding text, the text is the only thing that is blurry

    We better look at your code...

    ~ Timing is Everything! ~
  • Re: drawing text on graphics

    05-05-2008, 7:55 PM
    • Member
      232 point Member
    • ahmedilyas
    • Member since 04-15-2006, 1:52 AM
    • UK
    • Posts 313
    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.Save(path +
    "\\newone.jpg");

    b.Dispose();

    g.Dispose();

    }

    }

     

    C# MVP
  • Re: drawing text on graphics

    05-05-2008, 8:20 PM
    • Contributor
      2,349 point Contributor
    • geosync
    • Member since 03-26-2006, 8:44 PM
    • Boston, MA, USA
    • Posts 741

    I don't see anything unusual in this code.  Could you email a copy of your graphic with blurry text?

    ~ Timing is Everything! ~
  • Re: drawing text on graphics

    05-05-2008, 9:45 PM
    • Contributor
      2,349 point Contributor
    • geosync
    • Member since 03-26-2006, 8:44 PM
    • Boston, MA, USA
    • Posts 741
    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.
     
    HTH
     
    Good luck!
     
    Rick
    ~ Timing is Everything! ~
  • Re: drawing text on graphics

    05-05-2008, 9:58 PM
    • Contributor
      2,349 point Contributor
    • geosync
    • Member since 03-26-2006, 8:44 PM
    • Boston, MA, USA
    • Posts 741

    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

    ~ Timing is Everything! ~
  • Re: drawing text on graphics

    05-26-2008, 4:39 PM
    • Member
      85 point Member
    • pashaKasim
    • Member since 01-20-2006, 3:21 PM
    • Posts 25

    Hello GeoSync,

    Can you post an example how you can "outline" and "border" text, when you using DrawString.

     

    Thanx.

    Pk
  • Re: drawing text on graphics

    06-16-2008, 11:43 PM

    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

    Don't forget to mark as answer if this post helps!!

    --The Banjo Picker King
  • Re: drawing text on graphics

    01-18-2009, 1:40 AM
    • Member
      85 point Member
    • pashaKasim
    • Member since 01-20-2006, 3:21 PM
    • Posts 25

     @BanjoPickerKing

    Do you have an example how to use graphicspath?

     

    Thanx.

    Pk
  • Re: drawing text on graphics

    01-19-2009, 7:57 PM

     

    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.

    Don't forget to mark as answer if this post helps!!

    --The Banjo Picker King
  • Re: drawing text on graphics

    06-29-2009, 9:35 AM
    • Member
      22 point Member
    • aschaible
    • Member since 03-19-2008, 11:06 AM
    • Posts 6

    I was having a similar issue - but I switched to GIF output format and it's fine now. 

Page 1 of 1 (15 items)