I'm tying to change the ColorPalette of an EmguCV image, but the Palette does not change!
Sample code:
var img = new Image<Gray, byte>(10, 10);
ColorPalette pal = img.Bitmap.Palette;
pal.Entries[0] = Color.FromArgb(255, 0, 0, 255);
img.Bitmap.Palette = pal;
//img.Bitmap.Palette.Entries[0] != pal.Entries[0];
To me, it seems that the ColorPalette can't be changed. Also, the Entries property only has a getter, no setter.
But if you insist that it is possible to change the ColorPalette, I believe you. So, here's an idea on how to solve it then:
var img = new Image<Gray, byte>(10, 10);
Bitmap bmp = img.Bitmap;
ColorPalette pal = bmp.Palette;
pal.Entries[0] = Color.FromArgb(255, 0, 0, 255);
bmp.Palette = pal;
Image<Gray, byte> changedImage = new Image<Gray, byte>(bmp);
The idea is that you create a new image (or you can replace the old one by img = new Image<Gray, byte>(bmp);
) from the Bitmap where you have changed the ColorPalette. I haven't tried it myself, but I think it's worth a try!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.