且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将位图中的字节复制到字节数组然后再用Marshall复制

更新时间:2023-11-09 23:18:22

您没有显示如何创建第二个bmp来重新加载字节.但是PixelFormat8bbpIndexed,这意味着您的data数组将包含调色板索引而不是直接的颜色信息.当您创建第二个具有8位像素格式的bmp时,它将使用默认调色板,该调色板可能与原始调色板不同.

You did not show how you created the second bmp for reloading the bytes. But the PixelFormat is 8bbpIndexed, which means that your data array will contain palette indices instead of direct color information. When you create your second bmp with 8 bit pixel format it will use a default palette, which may be different from the original one.

因此,您必须保存第一张图像的bmp.Palette,然后使用它恢复第二张bmp实例的实际颜色.

So you must save the bmp.Palette of the first image, then use it to restore the actual colors of your second bmp instance.

更新:尽管可以一个一个地设置调色板条目,但是它没有任何作用.您必须设置整个调色板.此外,此处是带有索引位图操作(请参见ConvertPixelFormat)方法的帖子.

Update: Though you can set the palette entries one by one, it has no effect. You must set the whole palette instead. Additionally, here is a post with indexed bitmap manipulation (see the ConvertPixelFormat) method.