Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 851
simbolo Avatar asked Jul 23 '14 16:07

simbolo


1 Answers

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");
}
like image 76
dlemstra Avatar answered Sep 25 '22 19:09

dlemstra