ColorPalette class
-
How can it be used? The only thing I can do is retrieve the colors in the Entries. How can I change them? I'd like to change the palette of a 256 color gif. So I have Bitmap MyBitmap = new Bitmap("file.gif"); I tried MyBitmap.Palette.Entries[0] = Drawing.Color.Black, but it does nothing as Entries is a read only properties. How can I change the palette entries? Or how can I create a new ColorPalette? Bitmap.Palette is a read / write property, but there is no constructor for the ColorPalette class, and the ColorPalette.Entries are read only :confused:
-
How can it be used? The only thing I can do is retrieve the colors in the Entries. How can I change them? I'd like to change the palette of a 256 color gif. So I have Bitmap MyBitmap = new Bitmap("file.gif"); I tried MyBitmap.Palette.Entries[0] = Drawing.Color.Black, but it does nothing as Entries is a read only properties. How can I change the palette entries? Or how can I create a new ColorPalette? Bitmap.Palette is a read / write property, but there is no constructor for the ColorPalette class, and the ColorPalette.Entries are read only :confused:
ColorPalette
is a value-type. You can change a value of it when it's a property of another type. For more information about value types vs. reference types, see http://www.albahari.com/value%20vs%20reference%20types.html[^]. In order to change the palette, you must first get a copy of theColorPalette
struct:ColorPalette palette = img.Palette;
palette.Entries[0] = Color.Red;
img.Palette = palette;Microsoft MVP, Visual C# My Articles