Link to home
Start Free TrialLog in
Avatar of REA_ANDREW
REA_ANDREWFlag for United Kingdom of Great Britain and Northern Ireland

asked on

C# DrawString Quality

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
Avatar of InteractiveMind
InteractiveMind
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of REA_ANDREW

ASKER

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?
Oh.
hmm

Are you able to screenshot it, and upload it for us to see?
thankyou, an example can be found here

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

See the noise?
mhmm, I see it.

Could you post the extract of code you're using to produce that text please?
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;
    }
Do you get the noise if you write the response as a format other than JPEG?
Such as image/gif.
how do you set the quality of the Gif format?
ASKER CERTIFIED SOLUTION
Avatar of GhostMod
GhostMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial