simbolo
simbolo

Reputation: 7494

Create / Write EXIF data using Magick.NET

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?

Upvotes: 5

Views: 5904

Answers (1)

dlemstra
dlemstra

Reputation: 8153

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");
}

Upvotes: 6

Related Questions