How to draw a transparent gif in web

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
 
G

George Ter-Saakov

You have to explicity set transparent color.

See Bitmap.MakeTransparent
It might help.

George.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top