1

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

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

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

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

4

1 回答 1

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();
}
于 2012-10-18T17:58:21.877 回答