From 6c7dbe551680070ec37e7dc127e9d65005d6985f Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Mon, 24 Jul 2023 16:39:01 -0400 Subject: [PATCH] add focal length to EXIF display & tweak other EXIF display --- Program.cs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Program.cs b/Program.cs index 1f448ce..b0f66f2 100644 --- a/Program.cs +++ b/Program.cs @@ -146,6 +146,7 @@ public class Photo { public bool Loaded = false; public string? CameraModel; public string? LensModel; + public string FocalLength = ""; public string FNumber = ""; public string ExposureTime = ""; public string IsoSpeed = ""; @@ -164,7 +165,6 @@ public class Photo { image = await Image.LoadAsync(File); ExifProfile? exifs = image.Metadata.ExifProfile; if (exifs != null) { - Console.WriteLine("--------------------------------------"); // FIXME: handle Orientation IExifValue? model; if (exifs.TryGetValue(ExifTag.Model, out model)) { @@ -175,6 +175,12 @@ public class Photo { LensModel = lensModel.Value; } + IExifValue? focalLength; + if (exifs.TryGetValue(ExifTag.FocalLength, out focalLength)) { + Rational r = focalLength.Value; + FocalLength = $"{r.Numerator / r.Denominator}mm"; + } + IExifValue? fNumber; if (exifs.TryGetValue(ExifTag.FNumber, out fNumber)) { Rational r = fNumber.Value; @@ -205,12 +211,14 @@ public class Photo { IExifValue? isoSpeed; if (exifs.TryGetValue(ExifTag.ISOSpeedRatings, out isoSpeed)) { - ushort[] iso = isoSpeed.Value; - IsoSpeed = $"ISO {iso[0]}"; - } - foreach (IExifValue exif in exifs.Values) { - Console.WriteLine(exif.Tag.ToString() + " " + exif.GetValue().ToString()); + ushort[]? iso = isoSpeed.Value; + if (iso != null && iso.Length >= 1) { + IsoSpeed = $"ISO {iso[0]}"; + } } + // foreach (IExifValue exif in exifs.Values) { + // Console.WriteLine(exif.Tag.ToString() + " " + exif.GetValue().ToString()); + // } } } @@ -226,10 +234,10 @@ public class Photo { public string Description() { if (Loaded) { - string shootingInfo = $"{FNumber} at {ExposureTime}, {IsoSpeed}"; - return String.Format("{0,-30} {1,-50} {2}", shootingInfo, $"{CameraModel} {LensModel}", File); + string shootingInfo = $"{FocalLength}, {FNumber} at {ExposureTime}, {IsoSpeed}"; + return String.Format("{0,-40} {1,-50} {2}", shootingInfo, $"{CameraModel} {LensModel}", File); } else { - return String.Format("{0,-81} {1}", "", File); + return String.Format("{0,-90} {1}", "", File); } } } @@ -489,10 +497,12 @@ public class Game : GameWindow { GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); // Load textures from JPEGs. - // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); - string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); + string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); + // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); + // string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); + // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\"); for (int i = 0; i < files.Count(); i++) { string file = files[i]; @@ -500,7 +510,9 @@ public class Game : GameWindow { Photo photo = new Photo(file, TEXTURE_WHITE); photos.Add(photo); await Task.Run( () => { photo.Load(); }); - Console.WriteLine("file " + i); + if (photos.Count == 100) { + break; + } } } }