0

I'm trying to add metadata keywords to image files using 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.

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.

1 Answer 1

0

Okay, so after hours of debugging I've come to the conclusion that this problem is a bug in TagLib itself. 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. 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. If this property was never initialized, TagLib simply ignores trying to set the image.ImageTag.Keywords variable altogether.

So could anyone add to this and tell me if it's possible to get around this?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.