为什么将位图转换为8bpp会导致224个条目而不是256个条目?

时间:2012-10-18 17:01:35

标签: c# bitmap color-palette pixelformat

我正在尝试将现有位图转换为256色的调色板。

在网络上进行研究后,人们会建议:

Bitmap b1 = new Bitmap(picture);
Bitmap b2 = new Bitmap(b1.Size.Width,
                       b1.Size.Height,
                       System.Drawing.Imaging.PixelFormat.Format8bppIndexed);

当我调试并检查条目数时,它已将PixelFormat设置为256,但调色板仅包含224个条目

1 个答案:

答案 0 :(得分:0)

您使用的是哪个版本?此代码使用Visual Studio 2010(.NET 4.0)以调试模式编译,为我提供了256个条目的调色板。

private void button1_Click(object sender, EventArgs e)
{
    var b1 = new Bitmap(BITMAP_NAME);
    var b2 = new Bitmap(b1.Width, b1.Height, PixelFormat.Format8bppIndexed);
    int numColors = b2.Palette.Entries.Length;
    MessageBox.Show(String.Format("Palette contains {0} entries", numColors));
    b2.Dispose();
    b1.Dispose();
}