我在 C# 中加载 Tiff 文件时遇到问题。我下载了一些示例 tiff 文件并且能够很好地加载它们,但是当我尝试加载从 PCI Geomatica 或 ArcGIS 生成的任何 tiff 文件时,ReadRGBAImage 调用失败(返回 false)。除了 IMAGEWIDTH 和 IMAGELENGTH,我尝试检索的所有其他标签都返回了 null(例如 XRESOLUTION)。有没有人知道为什么会这样?相关代码如下:
using (Tiff tif = Tiff.Open(fileName, "r"))
{
// Find the width and height of the image
FieldValue[] value = tif.GetField(TiffTag.IMAGEWIDTH);
int width = value[0].ToInt();
value = tif.GetField(TiffTag.IMAGELENGTH);
int height = value[0].ToInt();
// Read the image into the memory buffer
int[] raster = new int[height * width];
if (!tif.ReadRGBAImage(width, height, raster))
{
System.Windows.Forms.MessageBox.Show("Could not read image");
return null;
}
}
谢谢!