Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for professional graphic designers and non-designers trying to do their own graphic design. It's 100% free, no registration required.

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.

share|improve this question
2  
Can you convert the files to .png before using them? I mean, why bother with a "broken" format? Or are they animations? –  John Jun 3 '13 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 Jun 3 '13 at 21:59
add comment

1 Answer

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:

share|improve this answer
    
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 Jun 3 '13 at 22:01
    
@Reuben: do the GIFs share an identical palette, or are they all different? –  Takkat Jun 4 '13 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 Jun 4 '13 at 6:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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