更改256色位图调色板中的颜色顺序

问题描述:

大家好.我需要在256色位图的ColorPalette中对颜色进行排序的帮助.

我加载了256色图片(Bitmap.FromFile),但我不对调色板中的颜色进行排序.事情是我需要将图像的背景(黑色)的颜色设置为调色板中的第一种颜色.

我不知道如何排序或更改颜色位置

请帮助:S

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

请参见此处.
我不确定您所说的排序"是什么意思.
但是,此链接可以帮助您开始读取位图".
See here.
I dont know for sure what you mean by "sort".
However this link can get you started with "reading a bitmap".


1.)256色位图由调色板条目组成(意味着每个像素对应一个调色板条目)
2.)如果要更改调色板输入顺序,则必须更改位图中的所有像素.
3.)如果要更改的颜色在调色板索引42上,则应变为调色板索引0:必须将所有较低的索引上移至+1,并将RGB存储到索引0.
4.)然后,您必须将位图< 42中的所有像素更改为index + 1,最后将所有像素== 42更改为0
就是这样-美好的一天.
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.


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