将 Tif 索引的 8 位颜色转换为 32 位颜色
我有一个索引 Tiff 图像,我正在使用 LibTiff.Net 读取该图像以生成大图像一部分的位图图像。我相信 Tiff 将有 256 个颜色条目,我想将其转换为 256 个 32 位像素值以在输出位图中使用。
int bitsPerSample = tif.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();
FieldValue[] colourIndex = tif.GetField(TiffTag.COLORMAP);
int[] palette = new int[256];
for( int i = 0; i < 256; i++ )
{
short red = colourIndex[0].ToShortArray()[i];
short green = colourIndex[1].ToShortArray()[i];
short blue = colourIndex[2].ToShortArray()[i];
palette[i] = ?
}
如何将 RGB Shorts 转换为 32 位像素值?
I have an indexed Tiff image which I'm reading using LibTiff.Net to produce a bitmap image of a section of the large image. I believe the Tiff will have 256 colour entries which I want to convert to 256 32-bit pixel values to be used in the output bitmap.
int bitsPerSample = tif.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();
FieldValue[] colourIndex = tif.GetField(TiffTag.COLORMAP);
int[] palette = new int[256];
for( int i = 0; i < 256; i++ )
{
short red = colourIndex[0].ToShortArray()[i];
short green = colourIndex[1].ToShortArray()[i];
short blue = colourIndex[2].ToShortArray()[i];
palette[i] = ?
}
How do I convert the RGB shorts into a 32-bit pixel value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 System.Drawing.Color.FromArgb(red, green, blue).ToArgb()。
但是,只有当 LibTiff 和 Win32 都对其 ARGB 值使用相同的字节顺序时,这才会给出正确的结果。它还假设您的红色、绿色和蓝色值在 0 到 255 范围内;如果没有,你可以缩放它们。
Try
System.Drawing.Color.FromArgb(red, green, blue).ToArgb()
.However, this will only give the right results if LibTiff and Win32 both use the same byte ordering for their ARGB values. It also assumes your red, green, and blue values are in the range 0 to 255; you can scale them if not.
在 TIFF ColorMap 中,每种颜色的值数为 2**BitsPerSample。因此,8 位调色板颜色图像的 ColorMap 字段将具有 3 * 256 个值。
每个值的宽度为 16 位。 0代表最小强度,65535代表最大强度。黑色用 0,0,0 表示,白色用 65535, 65535, 65535 表示。
因此,您可能应该使用以下代码:
In a TIFF ColorMap, the number of values for each color is 2**BitsPerSample. Therefore, the ColorMap field for an 8-bit palette-color image would have 3 * 256 values.
The width of each value is 16 bits. 0 represents the minimum intensity, and 65535 represents the maximum intensity. Black is represented by 0,0,0, and white by 65535, 65535, 65535.
So, you probably should use following code: