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



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

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

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

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

您正在使用什么版本?此代码,通过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();
}

最新更新