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

时间:2014-07-23 16:41:44

标签: c# imagemagick 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()时创建一个异常:

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数据?

1 个答案:

答案 0 :(得分:6)

您在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");
}
相关问题