private void CopyMetadataTo(BitmapMetadata dst, Metadata src) { // ApplicationName CopyStringTagTo(dst, "ApplicationName", src, ExifTagID.Software); // Author PropertyItem[] authorsPI = src.GetExifValues(ExifTagID.Artist); if (authorsPI.Length > 0) { List <string> authors = new List <string>(); foreach (PropertyItem pi in authorsPI) { string author = Exif.DecodeAsciiValue(pi); authors.Add(author); } ReadOnlyCollection <string> authorsRO = new ReadOnlyCollection <string>(authors); dst.Author = authorsRO; } CopyStringTagTo(dst, "CameraManufacturer", src, ExifTagID.Make); CopyStringTagTo(dst, "CameraModel", src, ExifTagID.Model); CopyStringTagTo(dst, "Copyright", src, ExifTagID.Copyright); CopyStringTagTo(dst, "Title", src, ExifTagID.ImageDescription); PropertyItem[] dateTimePis = src.GetExifValues(ExifTagID.DateTime); if (dateTimePis.Length > 0) { string dateTime = Exif.DecodeAsciiValue(dateTimePis[0]); try { dst.DateTaken = dateTime; } catch (Exception) { try { string newDateTime = FixDateTimeString(dateTime); dst.DateTaken = newDateTime; } catch (Exception) { // *shrug* } } } }
private void CopyStringTagTo(BitmapMetadata dst, string dstPropertyName, Metadata src, ExifTagID srcTagID) { PropertyItem[] pis = src.GetExifValues(srcTagID); if (pis.Length > 0) { PropertyInfo pi = dst.GetType().GetProperty(dstPropertyName); string piValue = Exif.DecodeAsciiValue(pis[0]); try { pi.SetValue(dst, piValue, null); } catch (Exception) { // *shrug* } } }