Using ImageMagick-based library Magick.NET in C# to add EXIF metadata to a processed JPEG that does not currently have an EXIF profile. Attempts to create a profile have all failed:
 var newExifProfile = image.GetExifProfile();
 if (newExifProfile == null)
 {
    newExifProfile = new ExifProfile();
 }
 newExifProfile.SetValue(ExifTag.Copyright, "test");
ExifProfile has other constructors that accept a stream or byte array, not providing one creates an exception whenever .SetValue() is called:
Object reference not set to an instance of an object. at ImageMagick.ExifReader.GetBytes(UInt32 length) at ImageMagick.ExifReader.Read(Byte[] data) at ImageMagick.ExifProfile.SetValue(ExifTag tag, Object value)
How can Magick.NET be used to write EXIF data?
You have found a bug in Magick.NET and this has been fixed (https://magick.codeplex.com/workitem/1272). With the next release of Magick.NET (6.8.9.601) you will be able to do this:
using (MagickImage image = new MagickImage("logo:"))
{
  profile = new ExifProfile();
  profile.SetValue(ExifTag.Copyright, "Dirk Lemstra");
  image.AddProfile(profile);
  image.Write("logo.withexif.jpg");
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With