private void ReadMetadata() { try { ExifTags.Clear(); if (CurrentPicture != null) { ExifTags.Add("=== METADATA ==="); IEnumerable <MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(CurrentPicture.Path); foreach (var directory in directories) { foreach (var tag in directory.Tags) { ExifTags.Add(directory.Name + " - " + tag.Name + " = " + tag.Description); } } } } catch (Exception ex) { Console.WriteLine("Error por asginación nula en CurrentPicture: " + ex.ToString()); } finally { RaisePropertyChanged("ExifTags"); } }
double Get24BitPosition(ExifReader reader, ExifTags tag, ExifTags alternateTag, out bool notFound) { Double[] positionValues; double position = default(double); notFound = true; try { if (reader.GetTagValue <Double[]>(tag, out positionValues)) { position = positionValues[0] + positionValues[1] / 60 + positionValues[2] / 3600; } notFound = double.IsNaN(position) || (Math.Abs(position) < 0.1); if (notFound && (reader.GetTagValue <Double[]>(alternateTag, out positionValues))) { position = positionValues[0] + positionValues[1] / 60 + positionValues[2] / 3600; notFound = double.IsNaN(position) || (Math.Abs(position) < 0.1); } } catch { } return(position); }
private static T SetExifData <T>(ExifReader reader, ExifTags tag) { T outValue; reader.GetTagValue(tag, out outValue); return(outValue); }
private T Get <T>(ExifReader reader, ExifTags tag, out bool notFound) { notFound = true; if (typeof(T) == typeof(string)) { string strValue = GetString(reader, tag, out notFound); return((T)Convert.ChangeType(strValue, typeof(T))); } T value = Activator.CreateInstance <T>(); bool isRead = false; try { isRead = reader.GetTagValue <T>(tag, out value); } catch { } if (isRead && Comparer <T> .Default.Compare(value, Activator.CreateInstance <T>()) != 0) { notFound = false; return(value); } return(value); }
private void btnOpen_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "JPEG Files (*.jpg)|*.jpg|All Files (*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { Image img = Image.FromFile(ofd.FileName); pictureBox.Image = img; _exif = new ExifTags(img); listExif.Items.Clear(); listExif.BeginUpdate(); foreach (ExifTag tag in _exif.Values) AddTagToList(tag); listExif.EndUpdate(); comboFields.Items.Clear(); foreach (string name in ExifTags.SupportedTagNames) comboFields.Items.Add(name); } }
private T Get <T>(ExifReader reader, ExifTags tag, ExifTags alternameTag, out bool notFound) { notFound = false; T value = Get <T>(reader, alternameTag, out notFound); return(notFound ? Get <T>(reader, alternameTag, out notFound) : value); }
private static void ReadExifString(ExifReader reader, ExifTags tag, ref List <GLTextureStream.ImageMetaData> meta) { string str; if (reader.GetTagValue(tag, out str)) { meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), 0.0f, str)); } }
private static void ReadExifRational(ExifReader reader, ExifTags tag, ref List <GLTextureStream.ImageMetaData> meta) { int[] rational; if (reader.GetTagValue(tag, out rational)) { float value = (float)rational[0] / (float)rational[1]; meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), value, value.ToString())); } }
private static void ReadExifLong(ExifReader reader, ExifTags tag, ref List <GLTextureStream.ImageMetaData> meta) { UInt32 num; if (reader.GetTagValue(tag, out num)) { meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), (float)num, num.ToString())); } }
private static void AssertStringValue(ExifReader reader, ExifTags tag, string expected) { string actual; if (!reader.GetTagValue(tag, out actual)) { Assert.Fail("Tag '{0}' not found.", tag); } Assert.AreEqual(expected, actual, "Tag '{0}' value mismatch."); }
private static double?GetCoordinate(this ExifLib.ExifReader reader, ExifTags type) { double[] coordinates; if (reader.GetTagValue(type, out coordinates)) { return(ToDoubleCoordinates(coordinates)); } return(null); }
private static void ReadExifDate(ExifReader reader, ExifTags tag, ref List <GLTextureStream.ImageMetaData> meta) { string str; if (reader.GetTagValue(tag, out str)) { DateTime date = DateTime.ParseExact(str, "yyyy:MM:dd HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture); meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), (float)date.Ticks, date.ToShortDateString())); } }
public void ExifTest() { PicasaEntry target = new PicasaEntry(); // TODO: Initialize to an appropriate value ExifTags expected = new ExifTags(); ExifTags actual; target.Exif = expected; actual = target.Exif; Assert.AreEqual(expected, actual); }
public static byte[] GetTagValueByteArray(ExifTags tag, ExifReader reader) { byte[] value = null; try { reader.GetTagValue <byte[]>(tag, out value); } catch { } return(value); }
public static double[] GetTagValueDoubleArray(ExifTags tag, ExifReader reader) { double[] valueDouble = null; try { reader.GetTagValue <double[]>(tag, out valueDouble); } catch { } return(valueDouble); }
private T ReadTag <T>(ExifTags tag) { var stream = File.OpenRead(this.FileName); using (ExifReader reader = new ExifReader(stream)) { T temp; if (reader.GetTagValue <T>(tag, out temp)) { return(temp); } return(default(T)); } }
private object GetObject(ExifReader reader, ExifTags tag, out bool notFound) { var tagname = tag.ToString().ToLower(); double db24 = Get24BitPosition(reader, tag, out notFound); if (!notFound) { return(db24); } DateTime dt = Get <DateTime>(reader, tag, out notFound); if (!notFound) { return(dt); } long lg = Get <long>(reader, tag, out notFound); if (!notFound) { return(lg); } double db = Get <double>(reader, tag, out notFound); if (!notFound) { return(db); } int num = Get <int>(reader, tag, out notFound); if (!notFound) { return(num); } var str = GetString(reader, tag, out notFound); if (!notFound) { return(str); } return(null); }
private bool HasValue <T>(ExifReader reader, ExifTags tag) { T defValue = Activator.CreateInstance <T>(); T value = Activator.CreateInstance <T>(); try { reader.GetTagValue <T>(tag, out value); return(Comparer <T> .Default.Compare(value, defValue) != 0); } catch { return(false); } }
private static Encoding GetEncoding(ExifTags tag) { switch (tag) { case ExifTags.Image_XPAuthor: case ExifTags.Image_XPTitle: case ExifTags.Image_XPKeywords: case ExifTags.Image_XPComment: case ExifTags.Image_XPSubject: return(Encoding.Unicode); default: return(Encoding.UTF8); } }
public static void SetExifTag(this Bitmap bitmap, ExifTags tag, string value) { var t = typeof(PropertyItem); var types = new Type[0]; var values = new object[0]; var ci = t.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, types, null); var pi = (PropertyItem)ci.Invoke(values); pi.Id = (int)tag; pi.Type = TagTypes.FromTag(tag); var bytes = ToBytes(tag, value); pi.Value = bytes; pi.Len = bytes.Length - 1; bitmap.SetPropertyItem(pi); }
public static string GetTagValueString(ExifTags tag, ExifReader reader) { string value = null; try { reader.GetTagValue <string>(tag, out value); } catch { } if (string.IsNullOrWhiteSpace(value) || string.IsNullOrEmpty(value)) { value = "<empty>"; } return(value); }
private static byte[] ToBytes(ExifTags tag, string value) { var encoding = GetEncoding(tag); switch (tag) { case ExifTags.Image_XPAuthor: case ExifTags.Image_XPTitle: case ExifTags.Image_XPKeywords: case ExifTags.Image_XPComment: case ExifTags.Image_XPSubject: return(encoding.GetBytes(value + "\0")); default: return(encoding.GetBytes(value + "\0")); } }
protected static void ProcessExifInfo(Image image, IDictionary <int, string> exifInfos) { ReadExif(exifInfos, image, ExifFileds.ImageWidth); ReadExif(exifInfos, image, ExifFileds.ImageHeight); ReadExif(exifInfos, image, ExifFileds.DateTimeOriginal); ReadExif(exifInfos, image, ExifFileds.Software); ReadExif(exifInfos, image, ExifFileds.ExposureTime); ReadExif(exifInfos, image, ExifFileds.ExposureProgram); ReadExif(exifInfos, image, ExifFileds.Make); ReadExif(exifInfos, image, ExifFileds.Model); ReadExif(exifInfos, image, ExifFileds.FocalLength); ReadExif(exifInfos, image, ExifFileds.ApertureValue); ReadExif(exifInfos, image, ExifFileds.MeteringMode); ReadExif(exifInfos, image, ExifFileds.ISOSpeedRatings); exifInfos.Add((int)ExifFileds.Flash, ExifTags.ReadTag(image, ExifFileds.Flash) == "关闭" ? "关闭" : "开启"); }
private void ProcessMetadata(ExifProfile exifProfile) { foreach (IExifValue entry in exifProfile.Values) { // todo: skip subIfd if (entry.DataType == ExifDataType.Ifd) { continue; } switch ((ExifTagValue)(ushort)entry.Tag) { case ExifTagValue.SubIFDOffset: case ExifTagValue.GPSIFDOffset: case ExifTagValue.SubIFDs: case ExifTagValue.XMP: case ExifTagValue.IPTC: case ExifTagValue.IccProfile: continue; } switch (ExifTags.GetPart(entry.Tag)) { case ExifParts.ExifTags: case ExifParts.GpsTags: break; case ExifParts.IfdTags: if (!IsPureMetadata(entry.Tag)) { continue; } break; } if (!this.Collector.Entries.Exists(t => t.Tag == entry.Tag)) { this.Collector.AddOrReplace(entry.DeepClone()); } } }
public void WriteOnlyExifTags_Works(TestImageWriteFormat imageFormat) { // Arrange Image <Rgba32> image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateRgba32Image(); image.Metadata.ExifProfile.Parts = ExifParts.ExifTags; // Act image = WriteAndRead(image, imageFormat); // Assert Assert.NotNull(image.Metadata.ExifProfile); Assert.Equal(7, image.Metadata.ExifProfile.Values.Count); foreach (IExifValue exifProfileValue in image.Metadata.ExifProfile.Values) { Assert.True(ExifTags.GetPart(exifProfileValue.Tag) == ExifParts.ExifTags); } image.Dispose(); }
public static double?GetTagValueDouble(ExifTags tag, ExifReader reader) { double?valueDouble = null; double value = 0; bool success = true; try { reader.GetTagValue <double>(tag, out value); } catch { } if (success) { valueDouble = Convert.ToDouble(value); } return(valueDouble); }
public void Ascii_Tag(ExifTags tag) { var guid = Guid.NewGuid(); var path = guid + ".jpg"; try { var source = guid.ToString(); using (var bitmap = new Bitmap(100, 100)) { bitmap.SetExifTag(tag, guid.ToString()); bitmap.Save(path, ImageFormat.Jpeg); } using (var bitmap = new Bitmap(path)) { var actual = bitmap.ReadExifTag(tag); actual.ShouldBe(source); } } finally { File.Delete(path); } }
public static int?GetTagValueInt32(ExifTags tag, ExifReader reader) { int? valueInt = null; UInt32 value = 0; bool success = true; try { reader.GetTagValue <UInt32>(tag, out value); } catch { success = false; } if (success) { valueInt = Convert.ToInt16(value); } return(valueInt); }
public static byte?GetTagValueByte(ExifTags tag, ExifReader reader) { byte?valueByte = null; byte value = 0; bool success = true; try { reader.GetTagValue <byte>(tag, out value); } catch { success = false; } if (success) { valueByte = (byte?)value; } return(valueByte); }
private string GetString(ExifReader reader, ExifTags tag, out bool notFound) { notFound = true; string value = null; bool isRead = false; try { isRead = reader.GetTagValue <string>(tag, out value); } catch { } if (isRead && !string.IsNullOrEmpty(value.Trim())) { notFound = false; return(value); } return(string.Empty); }
private static void ReadExifRational(ExifReader reader, ExifTags tag, ref List<GLTextureStream.ImageMetaData> meta) { int[] rational; if (reader.GetTagValue(tag, out rational)) { float value = (float)rational[0] / (float)rational[1]; meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), value, value.ToString())); } }
private void GetExifTag(ExifReader reader, ExifTags tag, string title, List<ExifData> list) { object value = null; if (reader.GetTagValue<object>(tag, out value)) { list.Add(new ExifData() { Key = title, Value = value.ToString() }); } }
private static void ReadExifDate(ExifReader reader, ExifTags tag, ref List<GLTextureStream.ImageMetaData> meta) { string str; if (reader.GetTagValue(tag, out str)) { DateTime date = DateTime.ParseExact(str, "yyyy:MM:dd HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture); meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), (float)date.Ticks, date.ToShortDateString())); } }
private static void ReadExifString(ExifReader reader, ExifTags tag, ref List<GLTextureStream.ImageMetaData> meta) { string str; if (reader.GetTagValue(tag, out str)) meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), 0.0f, str)); }
public bool GetTagValue <T>(ExifTags tag, out T result) { return(GetTagValue((ushort)tag, out result)); }
private static void ReadExifShort(ExifReader reader, ExifTags tag, ref List<GLTextureStream.ImageMetaData> meta) { UInt16 num; if (reader.GetTagValue(tag, out num)) meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), (float)num, num.ToString())); }