如何从Tif文件中获取Colormap

时间:2012-09-19 21:47:25

标签: c#

我的tif文件索引为8 bpp,并使用色彩图保存。

有没有办法从C#中的文件中恢复该色彩映射?

默认情况下,picturebox会自动显示这样的色彩图,因为最左边和右边代表0和255。

enter image description here

我在互联网上搜索它是徒劳的。

如果无法做到这一点,有人如何决定索引8 bpp图像的像素中的颜色?

1 个答案:

答案 0 :(得分:2)

假设您要编辑颜色贴图,您只需修改图像的调色板:

System.Drawing.Image image = Image.FromFile(@"Q:\my_image.tif");
System.Drawing.Imaging.ColorPalette palette = image.Palette;
//...palette.Entries is simply an array of System.Drawing.Color, modify to suit

//crucial step - palette was retrieved as a copy, so
//it is necessary to store the copy back to the image
image.Palette = palette;

如果您将图像保存为tiff,则修改后的调色板随之显示。