Click here to Skip to main content
12,299,131 members (49,931 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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 7-May-10 7:58am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

See here.
I dont know for sure what you mean by "sort".
However this link can get you started with "reading a bitmap".
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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));
}
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 12 Sep 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100