473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Background of text is mottled

Hi,

I'm using the code below to create a background and then write some
text on it. The area behind the text appears pixelated in the output
image. I've tried output to jpeg and gif but result is the same.

private void DrawImage()
{
string s = "A TEST CAPTION";
Rectangle frame;
Font f = new Font("Arial", 10);
SolidBrush sb;
Response.ContentType = "image/jpeg";

Bitmap bmp = new Bitmap(200, 24);
Graphics g = Graphics.FromImage(bmp);

//Draw caption area
sb = new SolidBrush(Color.Gray);
frame = new Rectangle(0, 0, 200, 24);
g.FillRectangle(sb, frame);

f = new Font("Arial", 10);
sb = new SolidBrush(Color.Black);
g.DrawString(s, f, sb, 8, 4);

// Send image
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

bmp.Dispose();
g.Dispose();
sb.Dispose();
}
Nov 18 '05 #1
5 1436
MarkMurphy wrote:
Hi,

I'm using the code below to create a background and then write some
text on it. The area behind the text appears pixelated in the output
image. I've tried output to jpeg and gif but result is the same.

private void DrawImage()
{
string s = "A TEST CAPTION";
Rectangle frame;
Font f = new Font("Arial", 10);
SolidBrush sb;
Response.ContentType = "image/jpeg";

Bitmap bmp = new Bitmap(200, 24);
Graphics g = Graphics.FromImage(bmp);

//Draw caption area
sb = new SolidBrush(Color.Gray);
frame = new Rectangle(0, 0, 200, 24);
g.FillRectangle(sb, frame);

f = new Font("Arial", 10);
sb = new SolidBrush(Color.Black);
g.DrawString(s, f, sb, 8, 4);

// Send image
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

bmp.Dispose();
g.Dispose();
sb.Dispose();
}

Two questions:
1: don't you have to call g.Save(); ?
2: does it get better if you add this line: g.SmoothingMode =
SmoothingMode.HighQuality; ?

Regards,
//Rutger
Nov 18 '05 #2
what about
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; ?
or
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; ?
or
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; ?

"MarkMurphy" <mu****@murphysw.com> wrote in message
news:e0**************************@posting.google.c om...
Hi,

I'm using the code below to create a background and then write some
text on it. The area behind the text appears pixelated in the output
image. I've tried output to jpeg and gif but result is the same.

private void DrawImage()
{
string s = "A TEST CAPTION";
Rectangle frame;
Font f = new Font("Arial", 10);
SolidBrush sb;
Response.ContentType = "image/jpeg";

Bitmap bmp = new Bitmap(200, 24);
Graphics g = Graphics.FromImage(bmp);

//Draw caption area
sb = new SolidBrush(Color.Gray);
frame = new Rectangle(0, 0, 200, 24);
g.FillRectangle(sb, frame);

f = new Font("Arial", 10);
sb = new SolidBrush(Color.Black);
g.DrawString(s, f, sb, 8, 4);

// Send image
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

bmp.Dispose();
g.Dispose();
sb.Dispose();
}

Nov 18 '05 #3
See if you have ClearType turned on; it sometimes causes some unusual
aliasing artifacts.

Display Properties/Appearance/Effects...

Tom Dacon
Dacon Software Consulting

"MarkMurphy" <mu****@murphysw.com> wrote in message
news:e0**************************@posting.google.c om...
Hi,

I'm using the code below to create a background and then write some
text on it. The area behind the text appears pixelated in the output
image. I've tried output to jpeg and gif but result is the same.

private void DrawImage()
{
string s = "A TEST CAPTION";
Rectangle frame;
Font f = new Font("Arial", 10);
SolidBrush sb;
Response.ContentType = "image/jpeg";

Bitmap bmp = new Bitmap(200, 24);
Graphics g = Graphics.FromImage(bmp);

//Draw caption area
sb = new SolidBrush(Color.Gray);
frame = new Rectangle(0, 0, 200, 24);
g.FillRectangle(sb, frame);

f = new Font("Arial", 10);
sb = new SolidBrush(Color.Black);
g.DrawString(s, f, sb, 8, 4);

// Send image
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

bmp.Dispose();
g.Dispose();
sb.Dispose();
}

Nov 18 '05 #4
Hi Mark,

As for this problem, infact it is some what caused by the image be
converted and color reduced by the web safe plate of the browser. This is
any very good means , but in addition to other members' suggestion , you
may also have a look at the following tech article:

#Optimizing Color Quantization for ASP.NET Images
http://msdn.microsoft.com/library/de...us/dnaspp/html
/colorquant.asp

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5
Thanks all for the suggestions. It turned out in my case that I needed
to use a web-safe color for the background and use one of the text
rendering hint values. Two problems, two solutions. Much
appreciated!

Mark
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Markus Mohr | last post by:
Hi, everyone, I have a special problem: For every monitor resolution in 200 pixel steps from 800 to 1600 pixels I have an image to be shown as centered background-image. Those images all...
11
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it possible to "feel" what the color of the background...
2
by: darkpowrjd | last post by:
I've been trying to create a new navigation system for my site, and I got everything figured out except for one thing. Here is the CSS code I'm using right now: body { font: normal 10px Verdana,...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
3
by: jacksoncn | last post by:
Hey everyone, I am havin a problem here, maybe someone could lend me their mind for a second. Here it is: I am using a repeat background on a y axis. When I am testing the file from my...
18
by: LayneMitch | last post by:
Hello. After getting great advice on positioning, I've edited my code and it's looking more stable. Now I need a little assistance with background image placement. Please click on this...
16
by: stevedude | last post by:
CSS newbie again. I have a problem trying to get coffee mug images within anchor tags to center with my link text for a vertical list menu. If I use the horizontal/vertical properties of...
10
by: VividWeb | last post by:
Hi. I am relatively new to CSS and HTML but have a basic understanding of most things. One of my backgrounds is not positioning correctly in IE 7 or AOL. The background behind the content...
2
by: thephatp | last post by:
I'm having a problem with IE rendering correctly. I'm experimenting with using all div's in my pages now, and I'm not very familiar with the quirks of IE. I have created a sample page, and I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.