How to draw a transparent gif in web

  • Thread starter Thread starter Minhua Fu
  • Start date Start date
M

Minhua Fu

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("images\\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
 
You have to explicity set transparent color.

See Bitmap.MakeTransparent
It might help.

George.
 
Back
Top