[.net] Changing gif palette

This topic is 3782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm working on an Admin for a web based product. One goal of the web product will generate images that correspond to the theme. Right now I am using all .gifs, because IE6 supports gif transparency (note it does not support transparency in pngs). The problem is that I am trying to find a way to change a color or two in the palette for the png. I tried looping through the palettes (Bitmap.Palette.Entries) and change these to the appropriate color, however it never changes the color in the image when saved. Another way I tried, was to create a 32bpp ARGB image, draw the gif on to it, loop thru each pixel, change the color manually, and then convert it to a gif on the Bitmap.Save() method. This worked, however I lost all transparency. What am I doing wrong?

Share on other sites
A common mistake is related to the way properties work, so this might be the reason it's not working for you?

If you're trying to modify the entries of the image's Palette directly, this won't work as you'll only be modifying a temporary copy of the ColorPalette returned by the Palette property's getter.

What you'll need to do is explicitly copy back the new ColorPalette, which can be done like this:

Image I;// ...ColorPalette P = I.Palette; // Get the palette.P.Entries[0] = Color.Red; // Modify the palette entries.I.Palette = P; // Copy the palette back to the image.

• 48
• 12
• 10
• 10
• 9
• Forum Statistics

• Total Topics
631380
• Total Posts
2999673
×