使用Magick.NET创建/写入EXIF数据 [英] Create / Write EXIF data using Magick.NET
问题描述
在C#中使用基于ImageMagick的库Magick.NET将EXIF元数据添加到当前没有EXIF配置文件的已处理JPEG中。尝试创建个人资料都失败了:
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
有其他接受流的构造函数或字节数组,不提供一个会在调用 .SetValue()
时创建异常:
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)
如何使用Magick.NET编写EXIF数据?
推荐答案
您在Magick.NET中发现了一个错误并且已修复( https://magick.codeplex.com/workitem/1272 )。随着Magick.NET的下一个版本(6.8.9.601)你将能够做到这一点:
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");
}
这篇关于使用Magick.NET创建/写入EXIF数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!