使用Magick.NET创建/写入EXIF数据

在C#中使用基于ImageMagick的库Magick.NET将EXIF元数据添加到当前没有EXIF配置文件的已处理JPEG中。 尝试创建配置文件都失败了:

var newExifProfile = image.GetExifProfile(); if (newExifProfile == null) { newExifProfile = new ExifProfile(); } newExifProfile.SetValue(ExifTag.Copyright, "test"); 

ExifProfile有其他构造函数接受一个流或字节数组,不提供一个在.SetValue()时创建一个exception:

 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) 

如何使用Magick.NET编写EXIF数据?

您在Magick.NET中发现了一个错误,并且已经修复( https://magick.codeplex.com/workitem/1272 )。 随着Magick.NET的下一个版本(6.8.9.601),你将能够做到这一点:

 using (MagickImage image = new MagickImage("logo:")) { profile = new ExifProfile(); profile.SetValue(ExifTag.Copyright, "Dirk Lemstra"); image.AddProfile(profile); image.Write("logo.withexif.jpg"); }