palette;
}
/// <summary>
/// 根据颜色深度,创建对应的调色板
/// </summary>
/// <param name="depth">颜色深度,即表示颜色所用的位数</param>
/// <returns>返回调色板</returns>
private ColorPalette CreateColorPalette(int depth)
{
//根据颜色数,决定使用什么样的调色板
PixelFormat pixelFormat = PixelFormat.Format1bppIndexed;
if (depth > 2)
pixelFormat = PixelFormat.Format4bppIndexed;
if (depth > 16)
pixelFormat = PixelFormat.Format8bppIndexed;
return CreateColorPalette(pixelFormat);
}
/// <summary>
/// 创建256级灰度调色板
/// </summary>
/// <returns>返回调色板</returns>
private ColorPalette CreateGrayscalePalette()
{
ColorPalette palette = CreateColorPalette(PixelFormat.Format8bppIndexed);
for (int i = 0; i < palette.Entries.Length; i++)
palette.Entries[i] = Color.FromArgb(255, i, i, i);
return palette;
}
}
/// <summary>
/// 根据颜色深度,创建对应的调色板
/// </summary>
/// <param name="depth">颜色深度,即表示颜色所用的位数</param>
/// <returns>返回调色板</returns>
private ColorPalette CreateColorPalette(int depth)
{
//根据颜色数,决定使用什么样的调色板
PixelFormat pixelFormat = PixelFormat.Format1bppIndexed;
if (depth > 2)
pixelFormat = PixelFormat.Format4bppIndexed;
if (depth > 16)
pixelFormat = PixelFormat.Format8bppIndexed;
return CreateColorPalette(pixelFormat);
}
/// <summary>
/// 创建256级灰度调色板
/// </summary>
/// <returns>返回调色板</returns>
private ColorPalette CreateGrayscalePalette()
{
ColorPalette palette = CreateColorPalette(PixelFormat.Format8bppIndexed);
for (int i = 0; i < palette.Entries.Length; i++)
palette.Entries[i] = Color.FromArgb(255, i, i, i);
return palette;
}