无法在位图中设置调色板
- 作者: boy辛苦掏粪给EXO吃了
- 来源: 51数据库
- 2022-10-20
问题描述
我一直在编写 PCX 解码器,到目前为止,PCX 图像本身解析得很好,但我不知道如何设置位图的调色板.
I have been writing a PCX decoder and, so far, the PCX image itself parses fine, but I can't work out how to set the palette of a bitmap.
我已经创建了一个像这样的位图:
I have created a bitmap like so:
Bitmap bmp = new Bitmap(width,
height,
stride2,
System.Drawing.Imaging.PixelFormat.Format8bppIndexed,
pixels);
但我似乎无法使用以下方法设置调色板:
But I can't seem to set the palette using the following method:
for (int i = 0; i < 256; i += 3)
{
Color b = new Color();
b = Color.FromArgb(palette[i], palette[i + 1], palette[i + 2]);
bmp.Palette.Entries.SetValue(b, i);
}
在这个例子中,我已经阅读了 pcx 文件调色板中的每个字节并将它们存储在调色板 [] 中.从那里,我用它来设置位图调色板中的条目.如何设置颜色?
In this example, I have read through each byte in the palette of the pcx file and stored them in palette[]. from there, I have used this to set the entries in the palette of the bitmap. How do I set the colours?
推荐答案
这也让我感到困惑.似乎 bitmap.Palette 返回位图调色板的克隆.一旦你修改了你的副本,你需要使用 bitmap.Palette = Palette 重置位图的调色板,例如
This had me confused too. It seems bitmap.Palette returns a clone of the bitmap's palette. Once you've modified your copy, you need to reset the bitmap's pallete by using bitmap.Palette = palette, e.g.
ColorPalette palette = bitmap.Palette; Color entries = palette.Entries; .... entries[i] = new Color(...); .... bitmap.Palette = palette; // The crucial statement
参见 http://www.charlespetzold.com/pwcs/PaletteChange.html
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
