不能设置位图调色板 [英] Can't set palette in bitmap

查看:240
本文介绍了不能设置位图调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在写一个PCX德codeR和,到目前为止,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 =调色板,例如

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

这篇关于不能设置位图调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆