public void ReplaceWithDataFrom(Metadata source) { OnChanging(); ++suppressChangeEvents; if (source != this && source.userMetaData != this.userMetaData) { Clear(); foreach (string key in source.userMetaData.Keys) { string value = source.userMetaData.Get(key); this.userMetaData.Set(key, value); } ReconstructExifInfoCache(); } --suppressChangeEvents; OnChanged(); }
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 CopyMetadataTo(Metadata dst, BitmapMetadata src) { dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Software, src.ApplicationName) }); ReadOnlyCollection<string> authors = src.Author; if (authors != null) { List<PropertyItem> piAuthors = new List<PropertyItem>(); foreach (string author in authors) { PropertyItem piAuthor = Exif.CreateAscii(ExifTagID.Artist, author); piAuthors.Add(piAuthor); } dst.AddExifValues(piAuthors.ToArray()); } dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Make, src.CameraManufacturer) }); dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Model, src.CameraModel) }); dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.Copyright, src.Copyright) }); dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.DateTime, src.DateTaken) }); dst.AddExifValues(new PropertyItem[1] { Exif.CreateAscii(ExifTagID.ImageDescription, src.Title) }); }
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* } } }