Ejemplo n.º 1
0
 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");
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        private static T SetExifData <T>(ExifReader reader, ExifTags tag)
        {
            T outValue;

            reader.GetTagValue(tag, out outValue);
            return(outValue);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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));
            }
        }
Ejemplo n.º 8
0
 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()));
     }
 }
Ejemplo n.º 9
0
        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()));
            }
        }
Ejemplo n.º 10
0
 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);
        }
Ejemplo n.º 12
0
        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()));
            }
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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.");
        }
        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);
        }
Ejemplo n.º 17
0
        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));
            }
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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);
            }
        }
Ejemplo n.º 20
0
        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);
            }
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 23
0
        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"));
            }
        }
Ejemplo n.º 24
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) == "关闭" ? "关闭" : "开启");
        }
Ejemplo n.º 25
0
            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());
                    }
                }
            }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 31
0
        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);
        }
Ejemplo n.º 32
0
 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()));
     }
 }
Ejemplo n.º 33
0
 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() });
     }
 }
Ejemplo n.º 34
0
 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()));
     }
 }
Ejemplo n.º 35
0
 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));
 }
Ejemplo n.º 36
0
 public bool GetTagValue <T>(ExifTags tag, out T result)
 {
     return(GetTagValue((ushort)tag, out result));
 }
Ejemplo n.º 37
0
 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()));
 }