我只想简单地更新我正在创建的tif映像上的EXIF_USERCOMMENT字段。
对SetField的调用失败。不知道我做错了什么。
这是我过于简单化的代码。
任何帮助都将不胜感激。
{
Tiff tiffdoc = Tiff.Open("C:\\temp\\~tempCapture.tif","rw");
bool bSetField = tiffdoc.SetField(TiffTag.EXIF_USERCOMMENT, "test comment field");
tiffdoc.WriteDirectory();
tiffdoc.Close();
}发布于 2014-04-23 17:51:15
不幸的是,看起来LibTiff.Net只能读取EXIF标记,而不能写入它们(原始的libtiff也不能写入EXIF标记)。
有一个关于为什么会这样的在libtiff邮件列表中的讨论。以下是讨论中的一些引语:
// FIXME -- we don't currently support writing of EXIF fields. TIFF
// in theory allows it, using a custom IFD directory, but at
// present, it appears that libtiff only supports reading custom
// IFD's, not writing them.伦纳德·罗森索尔:
I don't really think that libTIFF really wants to start down the
metadata "rabbit hole"... 鲍勃·弗里森哈恩:
I do agree with Leonard Rosenthol that libtiff should not be in the
business of dealing with EXIF private IFD tags (even though it
somewhat does already).至于Unknown tag EXIF_USERCOMMENT,您应该使用先读取EXIF目录。库将在读取EXIF目录之前将EXIF标记添加到其已知标记列表中,以后不会发出有关未知标记的错误。
但是库仍然无法将EXIF标记写入文件。
编辑:
如果只想在文件中存储一些信息,而不要求将其存储在EXIF_USERCOMMENT标记中,则可以使用一些选项。
您可以在任务中使用IMAGEDESCRIPTION标记。下面是使用此标记的示例代码。请注意,对于Open方法,代码使用不同的params,也使用RewriteDirectory而不是WriteDirectory。
string fileName = "C:\\temp\\~tempCapture.tif";
using (Tiff tiffdoc = Tiff.Open(fileName, "a"))
{
tiffdoc.SetDirectory(0);
bool bSetField = tiffdoc.SetField(TiffTag.IMAGEDESCRIPTION, "test comment field");
tiffdoc.RewriteDirectory();
}https://stackoverflow.com/questions/23204029
复制相似问题