REA_ANDREW
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
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
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?
hmm
Are you able to screenshot it, and upload it for us to see?
ASKER
thankyou, an example can be found here
http://www.nwcms.co.uk/andy/crossdesign/stories/ImageTitle.aspx?sid=1
See the noise?
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?
Could you post the extract of code you're using to produce that text please?
ASKER
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.ToIn t32(Reques t.QueryStr ing["sid"] ));
NewOne.Save(Response.Outpu tStream, 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_ima ges/bar.jp g"));
Graphics g = Graphics.FromImage(b);
SizeF TextWidth = g.MeasureString(Title, new Font("Arial Black", 14));
//g.Clear(Color.FromArgb(1 16, 147, 235));
SolidBrush Solid3 = new SolidBrush(Color.White);
g.TextRenderingHint = System.Drawing.Text.TextRe nderingHin t.AntiAlia sGridFit;
g.DrawString(Title, new Font("Arial Black", 14, FontStyle.Regular), Solid3, new Rectangle(0, 5, 444, 35));
g.Dispose();
return b;
}
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["sid"
{
Response.Clear();
Response.ContentType = "image/jpeg";
System.Drawing.Image NewOne = GenerateImage(Convert.ToIn
NewOne.Save(Response.Outpu
}
}
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("../
Graphics g = Graphics.FromImage(b);
SizeF TextWidth = g.MeasureString(Title, new Font("Arial Black", 14));
//g.Clear(Color.FromArgb(1
SolidBrush Solid3 = new SolidBrush(Color.White);
g.TextRenderingHint = System.Drawing.Text.TextRe
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.
Such as image/gif.
ASKER
how do you set the quality of the Gif format?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If so, then you could try apply the following to your Graphics instance prior to drawing the string:
myGraphicsInstance.Smoothi
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.