My suggestion was that if you needed a class
with the same behavior as ColorPalette, but with
a few changes, you could just copy the code from
the ColorPalette class to another class with the
name and additional functionality of your choice.
There are various tools for decompiling the framework.
But if you need to assign a ColorPalette object
to a property that expects the type found in the
framework, this might not be an option.
As for assigning a palette from a dummy palette
indirectly created by creating a new bitmap of the
same bit depth: No can do.
MyBitmap.Palett e = <ColorPalette object>
is not the same as
MyBitmap.Palett e = <some other bitmap>.Palette .
In the latter case, you are going through some
GDI+ functions to get a new palette rather than
just getting a ColorPalette object directly.
When assigned to MyBitmap.Palett e, you are
jumping through similar hoops.
Try the code below. You will find that nothing
works as expected. All copies are identical to
the original. Attempts to change the colors in
any of these manners are ignored.
I use an imaging toolkit for similar needs, so I
haven't digged deeper into this. There might be
a solution. Then again, there might not. It is possible
that Microsoft has made it *possible* to change the
Palette.Entries values, but not *intended* for them
to be changed or react to such changes.
Please prove me wrong.
Regards,
Joergen Bech
---snip---
'Load image
Dim lena8 As New Bitmap("d:\lena 8.bmp")
'Save it again to verify that we read it correctly
lena8.Save("d:\ lena8-original.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)
'Work with a palette created as a copy of the palette of the
original image
Dim cp As ColorPalette = lena8.Palette
For i As Integer = 0 To 255
cp.Entries(i) = Color.FromArgb( i, i, i)
Next
lena8.Palette = cp
lena8.Save("d:\ lena8-cp.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)
'Work with a dummy palette created by creating another bitmap
Dim bm As New Bitmap(1, 1, PixelFormat.For mat8bppIndexed)
For i As Integer = 0 To 255
bm.Palette.Entr ies(i) = Color.FromArgb( i, i, i)
Next
lena8.Palette = bm.Palette
lena8.Save("d:\ lena8-bm.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)
'Modify palette entries directly in the original image
For i As Integer = 0 To 255
lena8.Palette.E ntries(i) = Color.FromArgb( i, i, i)
Next
lena8.Save("d:\ lena8-0-255.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)
---snip---
On Sat, 14 Jul 2007 17:31:09 -0400, " active"
<ac********** @a-znet.comwrote:
>For each entry:
get an entry from a Bitmap color table
modify it
store the modified entry in a color table
Assign the new color table to the bitmap.
So I think I can do what the other posters suggested.
But I would like to know what you meant by the following.
>Just copy the class to MyColorPalette
Thanks