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

5

使用基于ImageMagick的Magick.NET库在C#中为处理后没有EXIF文件的JPEG添加EXIF元数据。尝试创建文件失败。

 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个回答

6

您在使用Magick.NET时发现了一个bug,并且已经被修复 (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");
}

你好,相关问题 - 有没有办法在Magick.NET中使用更多的自定义IPTC字段(从#220到#240的数字)?添加配置文件似乎会删除所有位于#220以上的现有IPTC记录,并且新闻机构经常使用超过20个自定义IPTC字段。如果我在ByteArray级别手动格式化配置文件,它能起作用吗? - yosh
你能在这里 https://magick.codeplex.com/discussions 或者这里 https://github.com/dlemstra/Magick.NET/issues 开始一个讨论吗?我还有一些问题。你能在信息中创建一个示例吗? - dlemstra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接