Visual C++ and gif (transparent background)

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Visual C++ and gif (transparent background)

Postby Hope80 » Thu May 19, 2005 4:33 pm

I am trying to create a gif image file with transparent background using Visual C++. However I am unsuccessful in my attempt. This is what I did. I load an existing gif file(with opaque background) into an IMAGE object. Then I get the color palette out of the gif and set 0 to the alpha value of the color I want to be transparent i.e. the background color. However the background still appears opaque. This is the reference I used:

http://support.microsoft.com/default.as ... Q315780#12

Pls kindly advise. Thanks.
Hope80
 
Posts: 4
Joined: Sat Mar 05, 2005 8:31 pm

Postby Hope80 » Thu May 19, 2005 7:06 pm

Here are my codes:

Code: Select all

      Image iconImage(L"c:\\Icon1.gif");

      DWORD palSize = iconImage.GetPaletteSize();
      ColorPalette* ppal = (ColorPalette*)new BYTE[palSize];
      iconImage.GetPalette(ppal, palSize);   

      int count = ppal->Count;
      for (int ii=0; ii<count; ii++) {
         Color color1 = ppal->Entries[ii];
         int red = color1.GetR();
         int green = color1.GetG();
         int blue = color1.GetB();
         
         if (ii == 0) {

            ppal->Entries[ii] = Color::MakeARGB(0, 0, 0, 0);
         }
         else
            ppal->Entries[ii] = Color::MakeARGB(0xFF, red, green, blue);

         
      }

      iconImage.SetPalette(ppal);

      iconImage.Save(L"\\transparent.gif", &encoderClsid, NULL);



The background I am trying to make it transparent is black.
Hope80
 
Posts: 4
Joined: Sat Mar 05, 2005 8:31 pm


Return to Games and Graphics

Who is online

Users browsing this forum: No registered users and 0 guests