How to draw a transparent gif in web

Discussion in 'ASP .Net' started by Minhua Fu, Dec 30, 2003.

  1. Minhua Fu

    Minhua Fu Guest

    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
    Minhua Fu, Dec 30, 2003
    #1
    1. Advertising

  2. You have to explicity set transparent color.

    See Bitmap.MakeTransparent
    It might help.

    George.


    "Minhua Fu" <> wrote in message
    news:ybiIb.5181$...
    > 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
    >
    >
    George Ter-Saakov, Dec 30, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew
    Replies:
    1
    Views:
    404
    Gregory Vaughan
    Nov 3, 2003
  2. Starlite
    Replies:
    2
    Views:
    4,217
    Victor Bazarov
    Dec 29, 2003
  3. aksel.schmidt
    Replies:
    11
    Views:
    1,098
    Andrew Thompson
    Dec 14, 2007
  4. aksel.schmidt
    Replies:
    0
    Views:
    387
    aksel.schmidt
    Dec 13, 2007
  5. fancyerii
    Replies:
    7
    Views:
    838
    Knute Johnson
    Aug 3, 2008
Loading...

Share This Page