By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,354 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,354 IT Pros & Developers. It's quick & easy.

How to draw a transparent gif in web

P: n/a
Hi,

I have a problem when I draw a transparent gif picture. I have an existing
transparent gif picture, i want to modify the gif and save it to
reponse.outstream. But the picture always keep black backgroup. Can anyone
give me some suggestions?

Following is my code.

System.Drawing.Image img =
System.Drawing.Image.FromFile(Server.MapPath("imag es\\menubutton.gif"));

bmWidth = img.Width;

bmHeight = img.Height;

Bitmap bm = new Bitmap(bmWidth, bmHeight);
Graphics g = Graphics.FromImage(bm);
stringSize = g.MeasureString(menuname, menuFont);
g.DrawImage(img, 0, 0);

g.DrawString(menuname, menuFont, new SolidBrush(Color.Black),

(bmWidth - stringSize.Width) / 2, (bmHeight - stringSize.Height) / 2);
Response.ContentType="image/gif";

bm.Save(Response.OutputStream, ImageFormat.Gif);

Thanks

Mike
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You have to explicity set transparent color.

See Bitmap.MakeTransparent
It might help.

George.
"Minhua Fu" <mi*******@sympatico.ca> wrote in message
news:yb********************@news20.bellglobal.com. ..
Hi,

I have a problem when I draw a transparent gif picture. I have an existing
transparent gif picture, i want to modify the gif and save it to
reponse.outstream. But the picture always keep black backgroup. Can anyone
give me some suggestions?

Following is my code.

System.Drawing.Image img =
System.Drawing.Image.FromFile(Server.MapPath("imag es\\menubutton.gif"));

bmWidth = img.Width;

bmHeight = img.Height;

Bitmap bm = new Bitmap(bmWidth, bmHeight);
Graphics g = Graphics.FromImage(bm);
stringSize = g.MeasureString(menuname, menuFont);
g.DrawImage(img, 0, 0);

g.DrawString(menuname, menuFont, new SolidBrush(Color.Black),

(bmWidth - stringSize.Width) / 2, (bmHeight - stringSize.Height) / 2);
Response.ContentType="image/gif";

bm.Save(Response.OutputStream, ImageFormat.Gif);

Thanks

Mike

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.