I use Magick.NET library for reading exif values. For highest performance I'm using Ping
method (see this) because I don't need actual image content when working with some image metadata.
But now I need to write exif tag value if this value not exists. What I'm trying to do:
public static void Test()
{
var path = @"C:\image.jpg";
using (var image = new MagickImage())
{
image.Ping(path);
var profile = image.GetExifProfile();
var copyright = profile.Values.FirstOrDefault(x => x.Tag == ExifTag.Copyright);
if (copyright != null)
{
Trace.WriteLine("Copyright: " + copyright);
}
else
{
Trace.WriteLine("Write Copyright data");
profile.SetValue(ExifTag.Copyright, "Example text");
image.AddProfile(profile, true);
image.Write(path);
}
}
}
But this code is not writing tag value to exif. I can successfully write tag value when opening file another way (like in this answer):
var path = @"C:\image.jpg";
// Read image with content
using (var image = new MagickImage(path))
{
// image.Ping(path) - no more need
var profile = image.GetExifProfile();
...
}
But this decode whole image content, I don't need it for changing values of 'content-independent' tags like Copyright or DateTimeDigitized.
The question is: how to edit this exif tags without loading whole image content?
And do I need to rewrite whole exif profile (image.AddProfile(profile, true)
) or there is some way to just edit profile?