gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:07:24 29 4
gpt4 key购买 nike

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

最佳答案

您在 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");
}

关于c# - 使用 Magick.NET 创建/写入 EXIF 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24916253/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com