Solved

C# DrawString Quality

Posted on 2006-07-24
10
2,872 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…

756 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