/// <summary> /// Ctor /// </summary> /// <param name="image">image from which to populate properties</param> public ImageMetaData(Bitmap image) : this(ExifReader.GetExifData(image, ImageMetaData.StandardTags)) { if (image != null) { // override EXIF with actual values if (image.Height > 0) { this.ImageHeight = image.Height; } if (image.Width > 0) { this.ImageWidth = image.Width; } } }
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 }
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; }