无法在位图中设置调色板

Can#39;t set palette in bitmap(无法在位图中设置调色板)
本文介绍了无法在位图中设置调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我一直在编写 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

这篇关于无法在位图中设置调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

ActiveDirectory error 0x8000500c when traversing properties(遍历属性时 ActiveDirectory 错误 0x8000500c)
search by samaccountname with wildcards(使用通配符按 samaccountname 搜索)
Get the list of Groups for the given UserPrincipal(获取给定 UserPrincipal 的组列表)
Can you find an Active Directory User#39;s Primary Group in C#?(你能在 C# 中找到 Active Directory 用户的主要组吗?)
Query From LDAP for User Groups(从 LDAP 查询用户组)
How can I get DOMAINUSER from an AD DirectoryEntry?(如何从 AD DirectoryEntry 获取 DOMAINUSER?)