Example #1
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);
            }
        }
Example #2
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;
        }