using (Tiff iimage = Tiff.Open("new.tif", "r"))
{
Tiff newiimage = Tiff.Open("newnew.tif", "w");
if (image == null)
{
MessageBox.Show("Could not open incoming image");
return;
}
using (StreamWriter writer = new StreamWriter("EnumerateTiffTags.txt"))
{
short numberOfDirectories = iimage.NumberOfDirectories();
for (short d = 0; d < numberOfDirectories; ++d)
{
iimage.SetDirectory((short)d);
for (ushort t = ushort.MinValue; t < ushort.MaxValue; ++t)
{
TiffTag tag = (TiffTag)t;
var value = iimage.GetField(tag);
if (value != null)
{
for (int j = 0; j < value.Length; j++)
{
writer.WriteLine("{0}", tag.ToString());
writer.WriteLine("{0} : {1}",
value[j].Value.GetType().ToString(), value[j].ToString());
}
newiimage.SetField(tag, value);// this line is giving me..
// an error "Unable to cast object of type 'BitMiracle.LibTiff.Classic.FieldValue[]'
// to type 'System.IConvertible'"
}
}
}
}
}
我正在打开一个读取标签值的文件并将它们写入另一个 TIFF 文件。问题出现在 SetField 函数中。我尝试调试它,一切似乎都很好,无法弄清楚为什么它会抛出错误。