public override object GetValue(object instance)
 {
     if (instance is ExifPropertyCollection)
     {
         ExifPropertyCollection exifs = (ExifPropertyCollection)instance;
         return(exifs[this.id]);
     }
     return(null);
 }
 public override void SetValue(object instance, object value)
 {
     if (instance is ExifPropertyCollection &&
         value is ExifProperty)
     {
         ExifPropertyCollection exifs = (ExifPropertyCollection)instance;
         exifs[this.id] = (ExifProperty)value;
         this.OnValueChanged(instance, EventArgs.Empty);
     }
 }
Пример #3
0
        /// <summary>
        /// Adds a collection of EXIF properties to an image.
        /// </summary>
        /// <param name="inputPath">file path of original image</param>
        /// <param name="outputPath">file path of modified image</param>
        /// <param name="properties"></param>
        public static void AddExifData(string inputPath, string outputPath, ExifPropertyCollection properties)
        {
            // minimally load image
            Image image;

            using (ExifReader.LoadImage(inputPath, out image))
            {
                using (image)
                {
                    ExifWriter.AddExifData(image, properties);
                    image.Save(outputPath);
                }
            }
        }
Пример #4
0
        public static void AddOrUpdate(this ExifPropertyCollection props, ExifTag tag, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }
            var old = props.FirstOrDefault(x => tag == x.Tag);

            if (null != old)
            {
                old.Value = value;
            }
            else
            {
                props.Add(tag, value);
            }
        }
Пример #5
0
        /// <summary>
        /// Adds a collection of EXIF properties to an image.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="properties"></param>
        public static void AddExifData(Image image, ExifPropertyCollection properties)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            if (properties == null || properties.Count < 1)
            {
                return;
            }

            foreach (ExifProperty property in properties)
            {
                ExifWriter.AddExifData(image, property);
            }
        }
        public override PropertyDescriptorCollection GetProperties(
            ITypeDescriptorContext context,
            object value,
            Attribute[] attributes)
        {
            PropertyDescriptor[]   descriptors = null;
            ExifPropertyCollection exifs       = value as ExifPropertyCollection;

            if (exifs != null)
            {
                descriptors = new PropertyDescriptor[exifs.Count];
                int i = 0;
                foreach (ExifProperty exif in (((ExifPropertyCollection)value)))
                {
                    descriptors[i++] = new ExifCollectionConverter.ExifPropertyDescriptor(exif.Tag, exif.DisplayName);
                }
            }
            return(new PropertyDescriptorCollection(descriptors));
        }
Пример #7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ImageFile"/> class.
		/// </summary>
		protected ImageFile ()
		{
			Format = ImageFileFormat.Unknown;
			Properties = new ExifPropertyCollection ();
            Encoding = Encoding.Default;
		}
Пример #8
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ImageFile" /> class.
 /// </summary>
 protected ImageFile()
 {
     Format     = ImageFileFormat.Unknown;
     Properties = new ExifPropertyCollection(this);
     Encoding   = Encoding.Default;
 }
Пример #9
0
        static void Main(string[] args)
        {
            // choose an image
            Console.Write("Enter image load path: ");
            string imagePath = Console.ReadLine();
            int    lastDot   = imagePath.LastIndexOf('.');

            Console.WriteLine();

            //----------------------------------------------

            // minimally loads image and closes it
            ExifPropertyCollection properties = ExifReader.GetExifData(imagePath);

            string dumpPath = imagePath.Substring(0, lastDot) + "_EXIF" + imagePath.Substring(lastDot) + ".txt";

            using (StreamWriter dumpWriter = File.CreateText(dumpPath))
            {
                // dump properties to console
                foreach (ExifProperty property in properties)
                {
                    dumpWriter.WriteLine("{0}.{1}: \"{2}\"",
                                         property.Tag.GetType().Name,
                                         property.Tag,
                                         property.DisplayName);
                    dumpWriter.WriteLine("{0}: {1}",
                                         GetPropertyTypeName(property.Value),
                                         property.Value);
                    dumpWriter.WriteLine("\"{0}\"",
                                         property.DisplayValue);
                    dumpWriter.WriteLine();
                }
            }

            Console.WriteLine();

            //----------------------------------------------
#if TEST
            string outputPath = imagePath.Substring(0, lastDot) + "_COPYRIGHT_LOREM_IPSUM" + imagePath.Substring(lastDot);
            Console.WriteLine("Adding dummy copyright to image and saving to:\r\n\t" + outputPath);

            // add copyright tag
            ExifProperty copyright = new ExifProperty();
            copyright.Tag   = ExifTag.Copyright;
            copyright.Value = String.Format(
                "Copyright (c){0} Lorem ipsum dolor sit amet. All rights reserved.",
                DateTime.Now.Year);

            ExifWriter.AddExifData(imagePath, outputPath, copyright);

            Console.WriteLine();

            //----------------------------------------------

            foreach (ExifTagOrientation i in Enum.GetValues(typeof(ExifTagOrientation)))
            {
                outputPath = imagePath.Substring(0, lastDot) + "_Orientation_" + (int)i + imagePath.Substring(lastDot);
                Console.WriteLine("Adding orientation to image and saving to:\r\n\t" + outputPath);

                // add orientation tag
                ExifProperty orientTag = new ExifProperty();
                orientTag.Tag   = ExifTag.Orientation;
                orientTag.Value = i;

                ExifWriter.AddExifData(imagePath, outputPath, orientTag);

                Console.WriteLine();
            }
#endif
        }
Пример #10
0
        private void updateImage(bool forceUpdate)
        {
            if (!Dispatcher.CheckAccess()) // CheckAccess returns true if you're on the dispatcher thread
            {
                Dispatcher.Invoke(() => updateImage(forceUpdate));
                return;
            }
            if (!IrfanWatcher.updateNeeded() && !forceUpdate)
            {
                return;
            }
            // choose an image
            //Console.Write("Enter image load path: ");
            string imagePath = IrfanWatcher.getFilePathToCurrentlyOpenedFileInIrfan();

            if (String.IsNullOrEmpty(imagePath))
            {
                return;
            }
            //Console.WriteLine();

            //----------------------------------------------

            // minimally loads image and closes it
            ExifPropertyCollection properties = ExifReader.GetExifData(imagePath);

            ExifProperty gpsLatitudeRefProperty = properties.FirstOrDefault(p => p.DisplayName == "GPS Latitude Ref");

            if (gpsLatitudeRefProperty == null)
            {
                setImageReplacement("Picture does not contain GPS information");
                return;
            }
            else
            {
                removeImageReplacement();
            }
            string gpsLatitudeRef = "";

            if (gpsLatitudeRefProperty != null)
            {
                gpsLatitudeRef = gpsLatitudeRefProperty.DisplayValue;
            }
            ExifProperty gpsLatitudeProperty = properties.First(p => p.DisplayName == "GPS Latitude");
            double       latitudeAsDouble    = 0;

            if (gpsLatitudeProperty != null)
            {
                ExifUtils.Rational <uint>[] latitudeAsRational = (ExifUtils.Rational <uint>[])gpsLatitudeProperty.Value;
                double latitudeDegree = latitudeAsRational[0].Numerator / latitudeAsRational[0].Denominator;
                double latitudeMinute = latitudeAsRational[1].Numerator / latitudeAsRational[1].Denominator;
                double latitudeSecond = latitudeAsRational[2].Numerator / latitudeAsRational[2].Denominator;
                latitudeAsDouble = latitudeDegree + latitudeMinute / 60 + latitudeSecond / 3600;
            }
            if (gpsLatitudeRef == "S")
            {
                latitudeAsDouble *= -1;
            }

            ExifProperty gpsLongitudeRefProperty = properties.First(p => p.DisplayName == "GPS Longitude Ref");
            string       gpsLongitudeRef         = "";

            if (gpsLongitudeRefProperty != null)
            {
                gpsLongitudeRef = gpsLongitudeRefProperty.DisplayValue;
            }
            ExifProperty gpsLongitudeProperty = properties.First(p => p.DisplayName == "GPS Longitude");
            double       longitudeAsDouble    = 0;

            if (gpsLongitudeProperty != null)
            {
                ExifUtils.Rational <uint>[] longitudeAsRational = (ExifUtils.Rational <uint>[])gpsLongitudeProperty.Value;
                double longitudeDegree = longitudeAsRational[0].Numerator / longitudeAsRational[0].Denominator;
                double longitudeMinute = longitudeAsRational[1].Numerator / longitudeAsRational[1].Denominator;
                double longitudeSecond = longitudeAsRational[2].Numerator / longitudeAsRational[2].Denominator;
                longitudeAsDouble = longitudeDegree + longitudeMinute / 60 + longitudeSecond / 3600;
            }
            if (gpsLongitudeRef == "W")
            {
                longitudeAsDouble *= -1;
            }

            int    picSizeHeight     = (int)this.Height;
            int    picSizeWidth      = (int)this.Width;
            string apiKey            = "";
            string mapType           = "roadmap";
            string floatFormatString = "F6";
            string center            = latitudeAsDouble.ToString(floatFormatString, CultureInfo.InvariantCulture.NumberFormat) + "," + longitudeAsDouble.ToString(floatFormatString, CultureInfo.InvariantCulture.NumberFormat); //"40.702147,-74.015794";
            string zoom           = zoomLevel.ToString();
            string markerLocation = center;
            string size           = picSizeWidth + "x" + picSizeHeight;

            System.Drawing.Image mapFromGMaps = null;
            if (String.IsNullOrEmpty(apiKey))
            {
                mapFromGMaps = GetImageFromUrl("http://maps.googleapis.com/maps/api/staticmap?center=" + center + "&maptype=" + mapType + "&zoom=" + zoom + "&markers=color:red|" + markerLocation + "&size=" + size); // + "&key=" + apiKey);
            }
            else
            {
                mapFromGMaps = GetImageFromUrl("http://maps.googleapis.com/maps/api/staticmap?center=" + center + "&maptype=" + mapType + "&zoom=" + zoom + "&markers=color:red|" + markerLocation + "&size=" + size + "&key=" + apiKey);
            }

            // ImageSource ...
            BitmapImage bi = new BitmapImage();

            bi.BeginInit();
            MemoryStream ms = new MemoryStream();

            // Save to a memory stream...
            mapFromGMaps.Save(ms, ImageFormat.Png);
            // Rewind the stream...
            ms.Seek(0, SeekOrigin.Begin);
            // Tell the WPF image to use this stream...
            bi.StreamSource = ms;
            bi.EndInit();
            mapImage.Source = bi;
        }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageFile"/> class.
 /// </summary>
 protected ImageFile()
 {
     Format = ImageFileFormat.Unknown;
     Properties = new ExifPropertyCollection ();
 }