Click here to Skip to main content
15,920,956 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi everyone. I need help sorting the color in the ColorPalette of a 256 colors bitmap.

I load a 256 colors picture (Bitmap.FromFile), but I do not how to sort the colors in the palette. The things is I need to set color of the background(black) of the image as the first color in the palette.

I have no idea how to sort it or change color positions

please help :S
Posted

1.) the 256 color bitmap consists of palette entries (means each pixel is corresponding to a palette entry)
2.) if you want to change the palette entry order you have to change all pixels in the bitmap.
3.) if the color you want to change is on palette index 42 should become to palette index 0: you MUST move all lower indexes up to +1 and store the RGB to index 0.
4.) Then you MUST change all pixels in the bitmap <42 to index+1 and finally all pixels ==42 to 0
Thats it - nice day.
 
Share this answer
 
See here.
I dont know for sure what you mean by "sort".
However this link can get you started with "reading a bitmap".
 
Share this answer
 
v3
C#
if (searching.PixelFormat == PixelFormat.Format8bppIndexed && dest.PixelFormat == PixelFormat.Format8bppIndexed)
{
    ColorPalette cp = dest.Palette;

    for (int index = 0; index < searching.Palette.Entries.Length; index++)
        cp.Entries[index] = searching.Palette.Entries[index];

    dest.Palette = cp;
    dest.Save(@"E:\Temp\" + Path.GetFileName(file.FilePath));
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900