编辑8bpp位图索引 [英] Editing 8bpp indexed Bitmaps

查看:253
本文介绍了编辑8bpp位图索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编辑8bpp的色的像素。由于这是的PixelFormat索引我知道,它采用了颜色表映射的像素值。尽管我可以将其转换为24 bpp的编辑位图,8bpp编辑快得多(VS 13毫秒3毫秒)。但是,在一些随机的RGB颜色访问8bpp位结果时改变每个值,即使的PixelFormat保持8bpp

i'm trying to edit the pixels of a 8bpp. Since this PixelFormat is indexed i'm aware that it uses a Color Table to map the pixel values. Even though I can edit the bitmap by converting it to 24bpp, 8bpp editing is much faster (13ms vs 3ms). But, changing each value when accessing the 8bpp bitmap results in some random rgb colors even though the PixelFormat remains 8bpp.

我目前正在开发的C#和算法如下:

I'm currently developing in c# and the algorithm is as follows:

(C#)

在8bpp 1加载原始位图

1- Load original Bitmap at 8bpp

2-创建具有相同大小与原始8bpp清空临时位图

2- Create Empty temp Bitmap with 8bpp with the same size as the original

这两个位图3 LockBits和,使用P / Invoke,调用C ++的方法,我通过每个BitmapData对象的SCAN0。 (我用的是C ++的方法通过位图的像素进行遍历时,因为它提供了更好的性能)

3-LockBits of both bitmaps and, using P/Invoke, calling c++ method where I pass the Scan0 of each BitmapData object. (I used a c++ method as it offers better performance when iterating through the Bitmap's pixels)

(C ++)

4-创建INT [256]调色板根据一些参数,并通过在调色板传递原始的像素值编辑临时位图字节。

4- Create a int[256] palette according to some parameters and edit the temp bitmap bytes by passing the original's pixel values through the palette.

(C#)

5 UnlockBits。

5- UnlockBits.

我的问题是我怎么能编辑的像素值,而不必奇怪的RGB颜色,甚至更好,编辑8bpp位图的颜色表?

My question is how can I edit the pixel values without having the strange rgb colors, or even better, edit the 8bpp bitmap's Color Table?

问候,

佩德罗

推荐答案

有没有必要进入C ++的土地或使用的P / Invoke在所有; C#支持指针和不安全code完美的罚款;我甚至可能大胆地猜测,这是造成你的问题。

There is no need to move into C++ land or use P/Invoke at all; C# supports pointers and unsafe code perfectly fine; I may even hazard a guess that this is causing your problems.

中的颜色可能从默认的调色板到来。你会发现,改变了调色板不应该是缓慢的。这是我做的,以创建一个灰度调色板:

The colors are likely coming from the default Palette. You'll find that changing the Palette shouldn't be slow at all. This is what I do to create a greyscale palette:

image = new Bitmap( _size.Width, _size.Height, PixelFormat.Format8bppIndexed);
ColorPalette pal = image.Palette;
for(int i=0;i<=255;i++) {
    // create greyscale color table
    pal.Entries[i] = Color.FromArgb(i, i, i);
}
image.Palette = pal; // you need to re-set this property to force the new ColorPalette

这篇关于编辑8bpp位图索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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