From d9043b05f830ccf87e1e314b9f9ea6a78b44eb62 Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 19 Sep 2024 14:19:06 +0200 Subject: [PATCH] Exif XPSubject conversion #145 --- src/PicView.Avalonia/Navigation/ExifHandling.cs | 2 +- src/PicView.Core/ImageDecoding/EXIFHelper.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/PicView.Avalonia/Navigation/ExifHandling.cs b/src/PicView.Avalonia/Navigation/ExifHandling.cs index 62e608538..db58eefee 100644 --- a/src/PicView.Avalonia/Navigation/ExifHandling.cs +++ b/src/PicView.Avalonia/Navigation/ExifHandling.cs @@ -216,7 +216,7 @@ public static void UpdateExifValues(ImageModel imageModel, MainViewModel vm) vm.GetDateTaken = EXIFHelper.GetDateTaken(profile); vm.GetCopyright = profile?.GetValue(ExifTag.Copyright)?.Value ?? string.Empty; vm.GetTitle = EXIFHelper.GetTitle(profile); - vm.GetSubject = profile?.GetValue(ExifTag.XPSubject)?.Value.ToString() ?? string.Empty; + vm.GetSubject = EXIFHelper.GetSubject(profile); vm.GetSoftware = profile?.GetValue(ExifTag.Software)?.Value ?? string.Empty; vm.GetResolutionUnit = EXIFHelper.GetResolutionUnit(profile); vm.GetColorRepresentation = EXIFHelper.GetColorSpace(profile); diff --git a/src/PicView.Core/ImageDecoding/EXIFHelper.cs b/src/PicView.Core/ImageDecoding/EXIFHelper.cs index f13bd4233..090fc38f5 100644 --- a/src/PicView.Core/ImageDecoding/EXIFHelper.cs +++ b/src/PicView.Core/ImageDecoding/EXIFHelper.cs @@ -469,4 +469,16 @@ public static string GetExifVersion(IExifProfile? profile) var titleTag = profile?.GetValue(ExifTag.ImageDescription)?.Value; return titleTag ?? string.Empty; } + + public static string? GetSubject(IExifProfile? profile) + { + var xPSubject = profile?.GetValue(ExifTag.XPSubject)?.Value; + var subject = xPSubject is null ? string.Empty : Encoding.ASCII.GetString(xPSubject); + if (!string.IsNullOrEmpty(subject)) + { + return subject; + } + var subjectTag = profile?.GetValue(ExifTag.XPSubject)?.Value; + return subjectTag?.GetValue(0)?.ToString() ?? string.Empty; + } } \ No newline at end of file