简体   繁体   English

如果没有关键字开头,则无法添加图片关键字,Taglib-Sharp

[英]Can't add image keywords if there were no keywords to begin with, Taglib-Sharp

I'm trying to add metadata keywords to image files using Taglib-Sharp. 我正在尝试使用Taglib-Sharp将元数据关键字添加到图像文件。 My problem is that the following code: 我的问题是以下代码:

image.ImageTag.Keywords = (string[])newTags.ToArray(typeof(string));
image.Save();

does nothing if there are no keywords in the file to begin with. 如果文件中没有关键字,则不执行任何操作。 If I open the file properties in Explorer and add tags manually first, it works just fine and adds the tags to the file. 如果我在资源管理器中打开文件属性,然后先手动添加标签,它就可以正常工作并将标签添加到文件中。

I've tried setting a breakpoint at the top of this method and I can see that image.ImageTag.Keywords has a length of zero, as it should at first, and the snippet (string[])newTags.ToArray(typeof(string)) does successfully return a populated string array, but after that line the image.ImageTag.Keywords variable still has a length of zero. 我尝试在此方法的顶部设置一个断点,然后可以看到image.ImageTag.Keywords的长度为零,就像开始时那样,它的长度为零,并且代码段(string[])newTags.ToArray(typeof(string))成功返回了一个填充的字符串数组,但是在那一行之后image.ImageTag.Keywords变量的长度仍然为零。

I'm totally stuck here, if I manually add at least one tag first everything works great. 我完全被困在这里,如果我首先手动添加至少一个标签,一切都会很好。 The problem only occurs when the file has no tags in it to start with. 仅当文件中没有标签开始时才会出现此问题。

Okay, so after hours of debugging I've come to the conclusion that this problem is a bug in TagLib itself. 好的,经过数小时的调试,我得出的结论是,此问题是TagLib本身的错误。 If a new image file is created and the meta keyword property for that file was NEVER changed manually, then TagLib seems to just ignore setting the image.ImageTag.Keywords array and just skips over it. 如果创建了新的图像文件,并且从未手动更改该文件的meta关键字属性,则TagLib似乎只是忽略了设置image.ImageTag.Keywords数组,而是跳过了它。 In order to get it to change the Keywords in the file, I must first manually add a tag to the file and then remove it. 为了使它能够更改文件中的关键字,我必须首先手动向文件添加标签,然后再将其删除。 This initializes the tag property in the file itself and therefore allows it to be set by TagLib. 这将初始化文件本身中的tag属性,因此允许TagLib对其进行设置。 If this property was never initialized, TagLib simply ignores trying to set the image.ImageTag.Keywords variable altogether. 如果从未初始化此属性,则TagLib完全忽略尝试完全设置image.ImageTag.Keywords变量的尝试。

So could anyone add to this and tell me if it's possible to get around this? 那么有人可以补充一下,告诉我是否有可能解决这个问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM