[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

grnerate a serverside gif-image from a textinput

stine.grith

1/20/2005 9:20:00 AM

We are generating a serverside gif-image from a textinput. The problem
is that we also are trying to draw a border around the text at the
image.

First we draw the image using Bitmap and graphics, then we use
GraphicsPath and Pen to draw the text, which is white with a black
border.

The problem is that the border is "following" the letter at the inside
and at the outside, which results in peaks at some letters, like A and
W.

The code we use is:

Response.ContentType="image/gif";
string field=Request.QueryString["text"];
string height = Request.QueryString["Size"];
Color myColor = ColorTranslator.FromHtml("#" +
Request.QueryString["BgColor"]);
if (field!=null)
{
Bitmap bm=new Bitmap(1,1);
int h = (int) Convert.ToInt32(height);
Font font = new Font("SteileFuturaBQ",h,FontStyle.Italic);
int fontStyle = (int)FontStyle.Italic;
StringFormat sf=new StringFormat(StringFormatFlags.NoWrap);
SizeF stringsize=Graphics.FromImage(bm).MeasureString(field, font);
bm=new Bitmap((int)(stringsize.Width), (int)(stringsize.Height));
System.Diagnostics.Debug.WriteLine(bm.Height);
System.Diagnostics.Debug.WriteLine(bm.Width);
Graphics gr=Graphics.FromImage(bm);
gr.FillRegion(Brushes.LightYellow, new Region(new RectangleF(0, 0,
bm.Width, bm.Height)));
gr.DrawRectangle(new Pen(Color.Black, 1), 0, 0, bm.Width-1,
bm.Height-1);
gr.SmoothingMode = SmoothingMode.AntiAlias;

GraphicsPath pth = new GraphicsPath();
pth.AddString(field.Trim(), font.FontFamily ,fontStyle, h ,new
Point(0,0), StringFormat.GenericTypographic);
Pen p = new Pen(Brushes.Black, 3.0f);
gr.DrawPath(p,pth);
gr.FillPath(Brushes.White,pth);
System.Diagnostics.Debug.WriteLine(bm.Height);
System.Diagnostics.Debug.WriteLine(bm.Width);
p.Dispose();
pth.Dispose();

bm.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
Response.Flush();
Response.End();

4 Answers

stine.grith

1/20/2005 12:12:00 PM

0

The problem with the border can be seen at:
http://projects.creuna.com/Gifgenerator/bugs-M...

best regards

Stine Grith

stine.gr...@creuna.dk wrote:
> We are generating a serverside gif-image from a textinput. The
problem
> is that we also are trying to draw a border around the text at the
> image.
>
> First we draw the image using Bitmap and graphics, then we use
> GraphicsPath and Pen to draw the text, which is white with a black
> border.
>
> The problem is that the border is "following" the letter at the
inside
> and at the outside, which results in peaks at some letters, like A
and
> W.
>
> The code we use is:
>
> Response.ContentType="image/gif";
> string field=Request.QueryString["text"];
> string height = Request.QueryString["Size"];
> Color myColor = ColorTranslator.FromHtml("#" +
> Request.QueryString["BgColor"]);
> if (field!=null)
> {
> Bitmap bm=new Bitmap(1,1);
> int h = (int) Convert.ToInt32(height);
> Font font = new Font("SteileFuturaBQ",h,FontStyle.Italic);
> int fontStyle = (int)FontStyle.Italic;
> StringFormat sf=new StringFormat(StringFormatFlags.NoWrap);
> SizeF stringsize=Graphics.FromImage(bm).MeasureString(field, font);
> bm=new Bitmap((int)(stringsize.Width), (int)(stringsize.Height));
> System.Diagnostics.Debug.WriteLine(bm.Height);
> System.Diagnostics.Debug.WriteLine(bm.Width);
> Graphics gr=Graphics.FromImage(bm);
> gr.FillRegion(Brushes.LightYellow, new Region(new RectangleF(0, 0,
> bm.Width, bm.Height)));
> gr.DrawRectangle(new Pen(Color.Black, 1), 0, 0, bm.Width-1,
> bm.Height-1);
> gr.SmoothingMode = SmoothingMode.AntiAlias;
>
> GraphicsPath pth = new GraphicsPath();
> pth.AddString(field.Trim(), font.FontFamily ,fontStyle, h ,new
> Point(0,0), StringFormat.GenericTypographic);
> Pen p = new Pen(Brushes.Black, 3.0f);
> gr.DrawPath(p,pth);
> gr.FillPath(Brushes.White,pth);
> System.Diagnostics.Debug.WriteLine(bm.Height);
> System.Diagnostics.Debug.WriteLine(bm.Width);
> p.Dispose();
> pth.Dispose();
>
> bm.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Gif);
> Response.Flush();
> Response.End();

Gnome

3/20/2010 6:58:00 PM

0

On Sat, 20 Mar 2010 12:50:28 -0400, Patriot Games
<Patriot@america.com> wrote:

>Who said "massive socialism?"

According to your idiots---it's so pervasive that we're collapsing

Of course us "liberals" know its a stupid belief

It's YOUR tinhats that seem to be unworking

Tom Sr.

3/20/2010 9:25:00 PM

0

On Mar 20, 2:57 pm, Gn...@cold.com wrote:
> On Sat, 20 Mar 2010 12:50:28 -0400, Patriot Games
> <Patr...@america.com> wrote:
> >Who said "massive socialism?"  
> -
> According to your idiots---it's so pervasive that we're collapsing
> Of course us "liberals" know its a stupid belief
> It's YOUR tinhats that seem to be unworking

"Nobody ever went broke underestimating the intelligence of the
American people".
-H.L. Mencken

Nobody ever went wrong underestimating the intelligence of Bob Milby
Jr., AKA "Patriot Games".

-Tom Sr.

Patriot Games

3/21/2010 9:07:00 PM

0

On Sat, 20 Mar 2010 11:57:33 -0700, Gnome@cold.com wrote:
>On Sat, 20 Mar 2010 12:50:28 -0400, Patriot Games
><Patriot@america.com> wrote:
>>Who said "massive socialism?"
>According to your idiots---it's so pervasive that we're collapsing

Who said "massive socialism?"

You...

Your attempt at SQUIRMING has FAILED.

YOU LIED.

How many people will waste their time replying to you knowing ALL of
YOUR posts are automatically DELETED by Google and ALL other Servers?