473,486 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to draw a transparent gif in web

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
1 1510
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8388
by: Starlite | last post by:
I am using Microsoft visual c++ 6, and I want to draw a shape (say a rectangle) on a view. The code that I have used is below, but this draws a solid -filled rectangle, what I want is a displayed...
21
3036
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do...
6
3977
by: felix | last post by:
Hi, I have an Image that is drawn with Graphics.DrawImage(..). What I want to do is drawing it with a given transparency, e.g. at an alpha of only 180 instead of 255. How am I doing that?!?!?...
1
2239
by: Robert W. | last post by:
I've successfully implemented code to change a form's background to a nice blue gradient. It looks great! But I'm having problems adding controls with transparent backgrounds to the form. ...
1
2996
by: Carsten Klotz | last post by:
Hi, I've set the TransparencyKey of a form to black. That means, all black pixel will be shown transparent within the drawing content of that form. If I set the background to black, I can see...
3
2479
by: Rich | last post by:
Hello, I need to draw some text on a form. No problem .... e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat) My problem is that I want to draw the text on top of some...
0
1520
by: Niu Kun | last post by:
Dear all, I'm planning to draw some overlapped pictures on a tabpage. I use PictureBox control. And the picture seems well at first. But when I try to draw a PictureBox on the other. The...
2
6559
by: Niu Kun | last post by:
Dear all, I'm trying to draw many overlapped PNG files with transparent background in imagebox control. But the transparent background in this control is rendered as the main control's...
10
7507
by: Phil | last post by:
I would like to draw some text which will be in front of any other controls, but without obscuring them completely. If I use DrawString in the form's Paint handler the text is always behind, not in...
0
6964
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
7123
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
7173
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...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4863
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...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.