Solved

C# DrawString Quality

Posted on 2006-07-24
10
2,854 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
Comment Utility
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
Comment Utility
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
Comment Utility
Oh.
hmm

Are you able to screenshot it, and upload it for us to see?
0
 
LVL 20

Author Comment

by:REA_ANDREW
Comment Utility
thankyou, an example can be found here

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

See the noise?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 25

Expert Comment

by:InteractiveMind
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
how do you set the quality of the Gif format?
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
Comment Utility
Closed, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network + 7 73
send mail from app.net 8 27
Windows Service with UDP 2 26
System.InvalidCastException: Specified cast is not valid 10 46
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now