I have some GIF files that are not observing transparency when I load them in .NET, via System.Drawing.Image.FromFile().

However, I have a some others that do.

When I have a look at the color palette, the ones that do work have argb(0,255,255,255) and the ones that don't work have argb(0,0,0,0).

Is it possible to change the color of this layer in the images that don't work to be argb(0,255,255,255)? I'm hoping this is going to solve my problem when loading in .NET.

Update: After 5 hours trying to work out why these particular images were not working for transparency, in my application, when others did, I eventually delivered the code and images to the test environment. And in that environment, they happened to work. Same code, same images. My conclusion is that there must be a runtime difference that prevents the transparency from working, perhaps a difference in .NET versions.

  • 2
    Can you convert the files to .png before using them? I mean, why bother with a "broken" format? Or are they animations?
    – John
    Commented Jun 3, 2013 at 8:05
  • I did try .png, but to no avail. I figured it might be easier to change argb(0,0,0,0) to argb(0,255,255,255) in a gif, rather than a PNG, although any instructions on doing that would be great as well.
    – Reuben
    Commented Jun 3, 2013 at 21:59
  • Re: working fine in the test environment but not in the dev environment: are you sure the old versions of the offending images (the ones you were using before you fixed the transparency colour) are not cached on your dev environment?
    – cockypup
    Commented Feb 24, 2015 at 16:25

1 Answer 1


Using the freeware tool Irfanview we can save any GIF file with a newly defined transparency color.

To do so open the GIF file with Irfanview to select "Save as..". Choose GIF as output format. The following dialog will open:

enter image description here

We now have the choice to give in a color number we wish to have transparent, or choose the transparent color before we save. The latter will open a preview window where we can select the desired transparent color with the mouse.

Alternatively we can also conver the transparency of a GIF file using convert from ImageMagick. Below example will make "black" transparent:

convert orig.gif -transparent black transp.gif

For further options, and how to identify the colors of a GIF see:

  • This is how to set an existing color in the image as the transparent color. I'm interested in changing the existing transparent color (argb(0,0,0,0)) to something else that doesn't already exist in the image (argb(0,255,255,255)), so it matches other images that get loaded into the same image context and share the palette.
    – Reuben
    Commented Jun 3, 2013 at 22:01
  • @Reuben: do the GIFs share an identical palette, or are they all different?
    – Takkat
    Commented Jun 4, 2013 at 6:05
  • I'm guessing they're different, although the transparent color is consistent at position 109. I had tried resaving the images, in which the transparency color was moved to 255. As mentioned in my updated, these files work in my test environment, but not in my development environment, so there may be something else in play that is messing things up.
    – Reuben
    Commented Jun 4, 2013 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.