Solved

C# DrawString Quality

Posted on 2006-07-24
10
2,875 Views
Last Modified: 2007-12-19
Hi,

When you use DrawString, say for Arial Black White on a RGB background. The quality of the color and the text is awful.  Does anyone know how I can get a crisp clean finish to the text and the background color?

thanks in advance

Andrew
0
Comment
Question by:REA_ANDREW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
10 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17167044
By awful, do you mean jagged (aliased) ?

If so, then you could try apply the following to your Graphics instance prior to drawing the string:

   myGraphicsInstance.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

In order to antialias the graphics.

Hopefully that will work for fonts as well.
If not however, then perhaps draw the text to your own Graphics instance, and run your own antialiasing algorithm to smooth it.
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17167062
when I say awful I mean like if I put a white font on a blue background I get tons of multicolored fine noise around the text and it looks like really low quality Gif. what would cause this?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17167069
Oh.
hmm

Are you able to screenshot it, and upload it for us to see?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17167085
thankyou, an example can be found here

http://www.nwcms.co.uk/andy/crossdesign/stories/ImageTitle.aspx?sid=1

See the noise?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17167109
mhmm, I see it.

Could you post the extract of code you're using to produce that text please?
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17167185
Certainly, thank you for your time

protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["sid"] != null)
        {
            Response.Clear();
            Response.ContentType = "image/jpeg";
            System.Drawing.Image NewOne = GenerateImage(Convert.ToInt32(Request.QueryString["sid"]));
            NewOne.Save(Response.OutputStream, ImageFormat.Jpeg);
        }
    }
    private System.Drawing.Image GenerateImage(int SID)
    {
        string StrSql = "SELECT story_title FROM story_view WHERE story_id =" + SID;
        SqlDataAdapter StoryAdp = new SqlDataAdapter(StrSql, MConn);
        DataSet StoryDs = new DataSet();
        StoryAdp.Fill(StoryDs);
        DataRow NewRow = StoryDs.Tables[0].Rows[0];
        string Title = NewRow[0].ToString();
        Bitmap b = new Bitmap(Server.MapPath("../layout_images/bar.jpg"));
        Graphics g = Graphics.FromImage(b);
        SizeF TextWidth = g.MeasureString(Title, new Font("Arial Black", 14));
        //g.Clear(Color.FromArgb(116, 147, 235));
        SolidBrush Solid3 = new SolidBrush(Color.White);
        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        g.DrawString(Title, new Font("Arial Black", 14, FontStyle.Regular), Solid3, new Rectangle(0, 5, 444, 35));
        g.Dispose();
        return b;
    }
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17167310
Do you get the noise if you write the response as a format other than JPEG?
Such as image/gif.
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17167404
how do you set the quality of the Gif format?
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 17323794
Closed, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I bind a WPF ComboBox to an ItemSource using XAML? 2 43
Need a simple RegEx to search for two words 27 120
"The resource cannot be found" 1 36
What are MicroServices? 4 65
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question