Jump to content
  • Advertisement
Sign in to follow this  
tHomahwk

[.net] Changing gif palette

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!