Solved

C# DrawString Quality

Posted on 2006-07-24
10
2,862 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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