ImageMagick C# How to Add JPEG EXIF TAGS

1.4k Views Asked by At

Using ImageMagick 8 for .Net in VS2013, Framework 4.6

I am trying to add exif tags to jpeg images,

My Code :

var exif = new ExifProfile();
exif.SetValue(ExifTag.Artist, "SM");
exif.SetValue(ExifTag.OwnerName, "ownerexample.com");
exif.SetValue(ExifTag.XPKeywords, "one two three");

the problem is that last line throws this: "exif Value should be an array"

also converting string into string array or byte array won't work,

  • am I using right tag (ExifTag.XPKeyWords) for adding Tags to jpeg?
  • if I am right then what is the right syntax to add tags to jpeg using ImageMagick?
1

There are 1 best solutions below

1
On BEST ANSWER

There is no version 8 of ImageMagick and I suspect that you are using Magick.NET. You are getting an exception because the XPKeywords should be a byte array instead of a string. You should do something like this:

Encoding.UTF8.GetBytes("one two three");

You can add the profile to the image with the following code:

image.AddProfile(exif);

Your operation will decode and encode the image. A tool like exiftool might be better if you just want to change the exif data as @fmw42 suggested.