【发布时间】:2009-11-25 11:45:52
【问题描述】:
在 Windows 7(和新的图像编解码器:WIC)之前,我使用以下(非常快速但肮脏)的方法来创建以白色为透明色的 Gif 编码图像:
MemoryStream target = new memoryStream(4096);
image.Save(target, imageFormat.Gif);
byte[] data = target.ToArray();
// Set transparency
// Check Graphic Control Extension signature (0x21 0xF9)
if (data[0x30D] == 0x21 && data[0x30E] == 0xF9)
data[0x313] = 0xFF; // Set palette index 255 (=white) as transparent
此方法有效,因为 .NET 过去使用标准调色板对 Gif 进行编码,其中索引 255 是白色。
但在 Windows 7 中,此方法不再有效。似乎标准调色板已更改,现在索引 251 是白色。但是我不确定。也许新的 Gif 编码器正在根据使用的颜色动态生成调色板?
我的问题:有没有人了解 Windows 7 的新 Gif 编码器,以及什么是使白色透明的好而快速的方法?
【问题讨论】: