/// <summary> /// Write Metadata to the Jpeg file, with no expection handling /// </summary> private void UnhandledWriteMetadata() { List <CompareResult> changes = new List <CompareResult>(); // Compare the two PhotoMetadataTools.CompareMetadata(this.InternalPhotoMetadataInFile, this.InternalPhotoMetadata, ref changes); // Save if there have been changes to the Metadata if (changes.Count > 0) { // Set the Last Edit Date this.Metadata.FotoflyDateLastSave = DateTime.Now; this.Metadata.CreationSoftware = FotoflyAssemblyInfo.ShortBuildVersion; // Read the file using (WpfFileManager wpfFileManager = new WpfFileManager(this.FileFullName, true)) { // Copy values across PhotoMetadataTools.WriteBitmapMetadata(wpfFileManager.BitmapMetadata, this.InternalPhotoMetadata); // Save file wpfFileManager.WriteMetadata(); // Save new BitmapMetadata as MetadataInFile this.InternalPhotoMetadataInFile = PhotoMetadataTools.ReadBitmapMetadata(wpfFileManager.BitmapMetadata); } } }
public static void ReadMetadata(string inputFile) { using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile)) { FileMetadata wpfMetadata = new FileMetadata(wpfFileManager.BitmapMetadata); Debug.WriteLine(wpfMetadata.ExifProvider.Aperture); } }
public void ReadXmpXapMetadata() { using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.SchemaXmpXap)) { XmpXapProvider xmpXapProvider = new XmpXapProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <string>(xmpXapProvider.CreatorTool, "Tassography PhotoManager"); Assert.AreEqual <Rating.Ratings>(xmpXapProvider.Rating.AsEnum, Rating.Ratings.FourStar); } }
public void ReadMetadataDump() { using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.SchemaXmpTiff)) { MetadataDump metadataDump = new MetadataDump(wpfFileManager.BitmapMetadata); // Check total count Assert.AreEqual <int>(metadataDump.StringList.Count, 187); } }
public void ReadXmpTiffMetadata() { using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.SchemaXmpTiff)) { XmpTiffProvider xmpTiffProvider = new XmpTiffProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <string>(xmpTiffProvider.Make, "Canon"); Assert.AreEqual <string>(xmpTiffProvider.Model, "Canon PowerShot SD790 IS"); Assert.AreEqual <string>(xmpTiffProvider.Orientation, "6"); Assert.AreEqual <string>(xmpTiffProvider.Software, "Tassography PhotoManager"); } }
/// <summary> /// Creates a small jpeg image containing a backup of all the metadata /// </summary> /// <param name="fileName">Filename of the file to create</param> /// <param name="overwrite">If true creates a new file, if false updates an existing file</param> public static void CreateMetadataBackup(JpgPhoto photo, string destinationFileName, bool overwrite) { if (!File.Exists(photo.FileFullName)) { throw new Exception("Source file does not exist: " + photo.FileFullName); } else if (File.Exists(destinationFileName) && overwrite) { File.Delete(destinationFileName); } // Check to see if we need to create a new image if (!File.Exists(destinationFileName)) { // Load source file using (Image sourceImage = Image.FromFile(photo.FileFullName)) { int destWidth = 0; int destHeight = 0; // Resize based on portrait\landscape // Multiple denominate by 1.0 to ensure we get decimal places if (sourceImage.Width < sourceImage.Height) { // Calculate new Width, use Max as Height destHeight = JpgPhotoTools.metadataBackupImageMaxDimension; destWidth = Convert.ToInt32(sourceImage.Width * (JpgPhotoTools.metadataBackupImageMaxDimension * 1.0 / sourceImage.Height)); } else { // Calculate new newHeight, use Max as Width destHeight = Convert.ToInt32(sourceImage.Height * (JpgPhotoTools.metadataBackupImageMaxDimension * 1.0 / sourceImage.Width)); destWidth = JpgPhotoTools.metadataBackupImageMaxDimension; } // Create the destination Bitmap Image destinationImage = new Bitmap(destWidth, destHeight, sourceImage.PixelFormat); // Create a graphics manipulate and paste in the source file Graphics destinationGraphic = Graphics.FromImage(destinationImage); destinationGraphic.CompositingQuality = CompositingQuality.HighQuality; destinationGraphic.SmoothingMode = SmoothingMode.HighQuality; destinationGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic; destinationGraphic.DrawImage(sourceImage, new Rectangle(0, 0, destWidth, destHeight)); // Save destinationImage.Save(destinationFileName, ImageFormat.Jpeg); } } // Update the new files metadata WpfFileManager.CopyBitmapMetadata(photo.FileFullName, destinationFileName); }
public static void WriteMetadata(string inputFile) { File.Copy(inputFile, "BitmapMetadataExamples.WriteMetadata.jpg", true); using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile, true)) { FileMetadata wpfMetadata = new FileMetadata(wpfFileManager.BitmapMetadata); wpfMetadata.IptcProvider.LocationCreatedCountry = "United States"; wpfFileManager.WriteMetadata(); } }
public void ReadXmpMicrosoftMetadata() { using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.SchemaXmpMicrosoft)) { XmpMicrosoftProvider xmpMicrosoftProvider = new XmpMicrosoftProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <Rating.Ratings>(xmpMicrosoftProvider.Rating.AsEnum, Rating.Ratings.ThreeStar); Assert.AreEqual <string>(xmpMicrosoftProvider.RegionInfo.Regions[0].PersonDisplayName, "Ben Vincent"); Assert.AreEqual <string>(xmpMicrosoftProvider.RegionInfo.Regions[0].PersonEmailDigest, "68A7D36853D6CBDEC05624C1516B2533F8F665E0"); Assert.AreEqual <string>(xmpMicrosoftProvider.RegionInfo.Regions[0].PersonLiveIdCID, "3058747437326753075"); Assert.AreEqual <string>(xmpMicrosoftProvider.RegionInfo.Regions[0].RectangleString, "0.2875, 0.191667, 0.182812, 0.24375"); } }
public void ReadMetadataTags() { string expectedString = "Île-de-France"; using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.TagsWithUnicode)) { Assert.AreEqual <string>(wpfFileManager.BitmapMetadata.Keywords.First(), expectedString, "Xmp Keywords"); Assert.AreEqual <string>(wpfFileManager.BitmapMetadata.Title, expectedString, "Title"); IptcProvider iptcProvider = new IptcProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <Tag>(iptcProvider.Keywords.First(), new Tag(expectedString), "Iptc Keywords"); } }
public static void UpdateWLPGRegions(string inputFile) { using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile, true)) { // Declare a bunch of XMP paths (see my last blog for details) string microsoftRegions = @"/xmp/MP:RegionInfo/MPRI:Regions"; string microsoftPersonDisplayName = @"/MPReg:PersonDisplayName"; string microsoftRectangle = @"/MPReg:Rectangle"; // Check the sourceMetadata contains a Region if (wpfFileManager.BitmapMetadata.ContainsQuery(microsoftRegions)) { // Get Region Data as BitmapMetadata BitmapMetadata regionsMetadata = wpfFileManager.BitmapMetadata.GetQuery(microsoftRegions) as BitmapMetadata; // Loop through each Region foreach (string regionQuery in regionsMetadata) { string regionFullQuery = microsoftRegions + regionQuery; // Grab Region metadata as BitmapMetadata BitmapMetadata regionMetadata = wpfFileManager.BitmapMetadata.GetQuery(regionFullQuery) as BitmapMetadata; // Change Rectangle & DisplayName to test values if (regionMetadata != null) { // If the region has a DisplayName, change the value if (regionMetadata.ContainsQuery(microsoftPersonDisplayName)) { regionMetadata.SetQuery(XmpMicrosoftQueries.RegionPersonDisplayName.Query, "test"); } // If the region has a DisplayName, change the value if (regionMetadata.ContainsQuery(microsoftRectangle)) { regionMetadata.SetQuery(XmpMicrosoftQueries.RegionRectangle.Query, "test"); } } // Write the Region back to Regions wpfFileManager.BitmapMetadata.SetQuery(regionFullQuery, regionMetadata); } // Write the Regions back to Root Metadata wpfFileManager.BitmapMetadata.SetQuery(microsoftRegions, regionsMetadata); } wpfFileManager.WriteMetadata(); } }
public void ReadExifGpsMetadata() { using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.GeotaggedExif1)) { GpsProvider gpsProvider = new GpsProvider(wpfFileManager.BitmapMetadata); // Expected 37° 48.41667 N 122° 25.38333 W Assert.AreEqual <GpsCoordinate>(gpsProvider.Latitude, new GpsCoordinate(GpsCoordinate.LatitudeRef.North, 37, 48.41667), "Latitude"); Assert.AreEqual <GpsCoordinate>(gpsProvider.Longitude, new GpsCoordinate(GpsCoordinate.LongitudeRef.East, 122, 25.38333), "Longitude"); Assert.AreEqual <string>(gpsProvider.DateTimeStamp.ToString("u"), "2009-10-10 21:46:24Z", "Satalite Time"); Assert.AreEqual <double>(gpsProvider.Altitude, -17.464, "Altitude"); Assert.AreEqual <GpsPosition.Dimensions>(gpsProvider.MeasureMode, GpsPosition.Dimensions.ThreeDimensional, "Measuremode"); Assert.AreEqual <string>(gpsProvider.VersionID, "2200", "Gps VersionID"); } }
public void WriteMetadataAndCheckForMetadataLoss() { JpgPhoto beforePhoto = TestPhotos.Load(TestPhotos.UnitTest3); JpgPhoto afterPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp5); // Copy Test file File.Copy(beforePhoto.FileFullName, afterPhoto.FileFullName, true); // Change date and save afterPhoto.Metadata.FotoflyDateLastSave = DateTime.Now.AddTicks(-DateTime.Now.TimeOfDay.Ticks); afterPhoto.WriteMetadata(); MetadataDump beforeDump; MetadataDump afterDump; using (WpfFileManager wpfFileManager = new WpfFileManager(beforePhoto.FileFullName)) { beforeDump = new MetadataDump(wpfFileManager.BitmapMetadata); beforeDump.GenerateStringList(); } using (WpfFileManager wpfFileManager = new WpfFileManager(afterPhoto.FileFullName)) { afterDump = new MetadataDump(wpfFileManager.BitmapMetadata); afterDump.GenerateStringList(); } for (int i = 0; i < beforeDump.StringList.Count; i++) { // Ignore schema changes, edit dates and created software if (beforeDump.StringList[i] != afterDump.StringList[i] && !beforeDump.StringList[i].Contains("DateLastSave") && !beforeDump.StringList[i].Contains("LastEditDate") && !beforeDump.StringList[i].Contains("ushort=513") && !beforeDump.StringList[i].Contains("OffsetSchema")) { Assert.Fail("Metadata mismatch " + beforeDump.StringList[i] + " != " + afterDump.StringList[i]); } } if (new FileInfo(afterPhoto.FileFullName).Length > new FileInfo(beforePhoto.FileFullName).Length) { Assert.Fail("Photo has decreased in size after saving"); } // Clean up File.Delete(afterPhoto.FileFullName); }
public void ReadXmpExifMetadata() { using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.SchemaXmpExif)) { XmpExifProvider xmpExifProvider = new XmpExifProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <string>(xmpExifProvider.FocalLength, "6200/1000"); Assert.AreEqual <Aperture>(xmpExifProvider.MaxApertureValue, new Aperture(95, 32)); Assert.AreEqual <Aperture>(xmpExifProvider.Aperture, new Aperture(80, 10)); Assert.AreEqual <string>(xmpExifProvider.ExifVersion, "0220"); Assert.AreEqual <MetadataEnums.MeteringModes>(xmpExifProvider.MeteringMode, MetadataEnums.MeteringModes.Pattern); Assert.AreEqual <IsoSpeed>(xmpExifProvider.IsoSpeed, new IsoSpeed(80)); Assert.AreEqual <string>(xmpExifProvider.WhiteBalance, "0"); Assert.AreEqual <double?>(xmpExifProvider.DigitalZoomRatio, 0.0); Assert.AreEqual <ExposureBias>(xmpExifProvider.ExposureBias, new ExposureBias("0/3")); } }
public void ReadIptcMetadata() { using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.SchemaXmpTiff)) { IptcProvider iptcProvider = new IptcProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <string>(iptcProvider.Byline, "Ben Vincent"); Assert.AreEqual <string>(iptcProvider.LocationCreatedCity, "San Mateo"); Assert.AreEqual <string>(iptcProvider.CopyrightNotice, "Tassography"); Assert.AreEqual <string>(iptcProvider.LocationCreatedCountry, "United States"); Assert.AreEqual <string>(iptcProvider.LocationCreatedRegion, "California"); Assert.AreEqual <string>(iptcProvider.LocationCreatedSubLocation, "San Mateo County Expo Center"); Assert.AreEqual <DateTime>(iptcProvider.DateCreated, new DateTime(2008, 05, 04)); Assert.AreEqual <TimeSpan>(iptcProvider.TimeCreated, new TimeSpan(20, 29, 00)); } }
public void MetadataFromImage(string image) { JpgPhoto mainPhoto = new JpgPhoto(image); _mainPictureFilename = image; _lat = mainPhoto.Metadata.GpsPositionOfLocationCreated.Latitude.Numeric; _lon = mainPhoto.Metadata.GpsPositionOfLocationCreated.Longitude.Numeric; _alt = mainPhoto.Metadata.GpsPositionOfLocationCreated.Altitude; //TODO: We need a Fotofly method for retrieving the compass metadata. //No standard in JpgPhoto class. We add references to PresentationCore and WindowsBase //from .NET 3.0 WpfFileManager wpf = new WpfFileManager(image, false); URational urational = wpf.BitmapMetadata.GetQuery <URational>(GpsQueries.ImgDirection.Query); _compass = urational.ToDouble(3); }
public void ReadXmpGpsMetadata() { using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.GeotaggedXmp1)) { // Expected 51° 55.6784 N 4° 26.6922 E XmpExifProvider xmpExifProvider = new XmpExifProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <GpsCoordinate>(xmpExifProvider.GpsLatitude, new GpsCoordinate(GpsCoordinate.LatitudeRef.North, 51, 55.6784), "Latitude"); Assert.AreEqual <GpsCoordinate>(xmpExifProvider.GpsLongitude, new GpsCoordinate(GpsCoordinate.LongitudeRef.East, 4, 26.6922), "Longitude"); Assert.AreEqual <double>(xmpExifProvider.GpsAltitude, Double.NaN, "Altitude"); Assert.AreEqual <string>(xmpExifProvider.GpsVersionID, "2.2.0.0", "Gps VersionID"); Assert.AreEqual <string>(xmpExifProvider.GpsDateTimeStamp.ToString("u", DateTimeFormatInfo.InvariantInfo), "2010-02-01 22:02:34Z", "Satalite Time"); } using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.GeotaggedXmp2)) { // Expected 51° 55.7057 N 4° 26.9547 E XmpExifProvider xmpExifProvider = new XmpExifProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <GpsCoordinate>(xmpExifProvider.GpsLatitude, new GpsCoordinate(GpsCoordinate.LatitudeRef.North, 51, 55.7057)); Assert.AreEqual <GpsCoordinate>(xmpExifProvider.GpsLongitude, new GpsCoordinate(GpsCoordinate.LongitudeRef.East, 4, 26.9547)); Assert.AreEqual <string>(xmpExifProvider.GpsDateTimeStamp.ToString("u"), "2010-02-01 22:25:12Z"); } using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.GeotaggedXmp3)) { // Expected 51° 55.6767 N 4° 27.2393 E XmpExifProvider xmpExifProvider = new XmpExifProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <GpsCoordinate>(xmpExifProvider.GpsLatitude, new GpsCoordinate(GpsCoordinate.LatitudeRef.North, 51, 55.6767)); Assert.AreEqual <GpsCoordinate>(xmpExifProvider.GpsLongitude, new GpsCoordinate(GpsCoordinate.LongitudeRef.East, 4, 27.2393)); Assert.AreEqual <string>(xmpExifProvider.GpsDateTimeStamp.ToString("u"), "2010-02-01 23:35:07Z"); } using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.GeotaggedXmp4)) { // Expected: GPSAltitude 2/1 GPSLatitude 51,55.4804N GPSLongitude 4,27,9E XmpExifProvider xmpExifProvider = new XmpExifProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <GpsCoordinate>(xmpExifProvider.GpsLatitude, new GpsCoordinate(GpsCoordinate.LatitudeRef.North, 51, 55.4804)); Assert.AreEqual <GpsCoordinate>(xmpExifProvider.GpsLongitude, new GpsCoordinate(GpsCoordinate.LongitudeRef.East, 4, 27, 9)); Assert.AreEqual <string>(xmpExifProvider.GpsDateTimeStamp.ToString("u"), "2010-02-01 23:00:52Z"); } }
public static void ReadGpsAltitude(string inputFile) { // Grab copy of BitmapMetadata using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile)) { // Grab the GpsAltitudeRef string altitudeRef = wpfFileManager.BitmapMetadata.GetQuery("/app1/ifd/Gps/subifd:{uint=5}").ToString(); // Grab GpsAltitude as a ulong ulong rational = (ulong)wpfFileManager.BitmapMetadata.GetQuery("/app1/ifd/Gps/subifd:{uint=6}"); // Now shift & mask out the upper and lower parts to get the numerator and the denominator uint numerator = (uint)(rational & 0xFFFFFFFFL); uint denominator = (uint)((rational & 0xFFFFFFFF00000000L) >> 32); // And finally turn it into a double double altitude = Math.Round(Convert.ToDouble(numerator) / Convert.ToDouble(denominator), 3); } }
public void WriteTextMetadata() { File.Copy(this.samplePhotosFolder + TestPhotos.UnitTest1, this.samplePhotosFolder + TestPhotos.UnitTestTemp2, true); string testString = " " + DateTime.Now.ToString(); using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.UnitTestTemp2, true)) { FileMetadata fileMetadata = new FileMetadata(wpfFileManager.BitmapMetadata); fileMetadata.Description = "Description" + testString; fileMetadata.Comment = "Comment" + testString; fileMetadata.Copyright = "Copyright" + testString; fileMetadata.Subject = "Subject" + testString; wpfFileManager.WriteMetadata(); } using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.UnitTestTemp2)) { FileMetadata fileMetadata = new FileMetadata(wpfFileManager.BitmapMetadata); Assert.AreEqual <string>(fileMetadata.Description, "Description" + testString, "Description"); Assert.AreEqual <string>(fileMetadata.Comment, "Comment" + testString, "Comment"); Assert.AreEqual <string>(fileMetadata.Copyright, "Copyright" + testString, "Copyright"); Assert.AreEqual <string>(fileMetadata.Subject, "Subject" + testString, "Subject"); // Check underlying Description values Assert.AreEqual <string>(fileMetadata.IptcProvider.Caption, "Description" + testString, "Iptc.Caption"); Assert.AreEqual <string>(fileMetadata.ExifProvider.Description, "Description" + testString, "Exif.Description"); // TODO Add unerlying check for: // Xmp dc:title // Xmp dc:description } // Clean up from previous test if (File.Exists(this.samplePhotosFolder + TestPhotos.UnitTestTemp2)) { File.Delete(this.samplePhotosFolder + TestPhotos.UnitTestTemp2); } }
public static void ReadIPTCAddress(string inputFile) { // Queries for the IPTC Address fields // Note: Region is normally the State or County // iptcCountry = "/app13/irb/8bimiptc/iptc/Country\/Primary Location Name"; // iptcRegion = "/app13/irb/8bimiptc/iptc/Province\/State"; // iptcCity = "/app13/irb/8bimiptc/iptc/City"; // iptcSubLocation = "/app13/irb/8bimiptc/iptc/Sub-location"; string iptcCity = @"/app13/irb/8bimiptc/iptc/City"; using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile)) { // Check there's city data if (wpfFileManager.BitmapMetadata.ContainsQuery(iptcCity)) { // Dump it to the console Debug.WriteLine(wpfFileManager.BitmapMetadata.GetQuery(iptcCity)); } } }
/// <summary> /// Read Metadata from the Jpeg file, with no expection handling /// </summary> private void UnhandledReadMetadata() { this.InternalPhotoMetadata = new PhotoMetadata(); this.InternalPhotoMetadataInFile = new PhotoMetadata(); // Read BitmapMetadata using (WpfFileManager wpfFileManager = new WpfFileManager(this.FileFullName)) { // Copy that gets changed this.InternalPhotoMetadata = PhotoMetadataTools.ReadBitmapMetadata(wpfFileManager.BitmapMetadata, wpfFileManager.BitmapDecoder); this.InternalPhotoMetadata.ImageHeight = wpfFileManager.BitmapDecoder.Frames[0].PixelHeight; this.InternalPhotoMetadata.ImageWidth = wpfFileManager.BitmapDecoder.Frames[0].PixelWidth; // Copy saved metadata for comparisons this.InternalPhotoMetadataInFile = PhotoMetadataTools.ReadBitmapMetadata(wpfFileManager.BitmapMetadata, wpfFileManager.BitmapDecoder); this.InternalPhotoMetadataInFile.ImageHeight = wpfFileManager.BitmapDecoder.Frames[0].PixelHeight; this.InternalPhotoMetadataInFile.ImageWidth = wpfFileManager.BitmapDecoder.Frames[0].PixelWidth; } }
public void WriteFotoflyMetadata() { // Copy file File.Copy(this.samplePhotosFolder + TestPhotos.UnitTest1, this.samplePhotosFolder + TestPhotos.UnitTestTemp1, true); // Test Values DateTime testDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.UnitTestTemp1, true)) { XmpFotoflyProvider xmpFotoflyProvider = new XmpFotoflyProvider(wpfFileManager.BitmapMetadata); xmpFotoflyProvider.AddressCreatedLookupDate = testDate; xmpFotoflyProvider.AddressCreatedSource = "Bing Maps for Enterprise"; xmpFotoflyProvider.DateLastSave = testDate; xmpFotoflyProvider.OriginalCameraDate = testDate; xmpFotoflyProvider.OriginalCameraFilename = "img_123.jpg"; xmpFotoflyProvider.DateUtc = testDate; xmpFotoflyProvider.UtcOffset = 5; wpfFileManager.WriteMetadata(); } using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.UnitTestTemp1)) { XmpFotoflyProvider xmpFotoflyProvider = new XmpFotoflyProvider(wpfFileManager.BitmapMetadata); Assert.AreEqual <DateTime>(xmpFotoflyProvider.AddressCreatedLookupDate, testDate); Assert.AreEqual <string>(xmpFotoflyProvider.AddressCreatedSource, "Bing Maps for Enterprise"); Assert.AreEqual <DateTime>(xmpFotoflyProvider.DateLastSave, testDate); Assert.AreEqual <DateTime>(xmpFotoflyProvider.OriginalCameraDate, testDate); Assert.AreEqual <string>(xmpFotoflyProvider.OriginalCameraFilename, "img_123.jpg"); Assert.AreEqual <DateTime>(xmpFotoflyProvider.DateUtc, testDate); Assert.AreEqual <double>(xmpFotoflyProvider.UtcOffset.Value, 5); } if (File.Exists(this.samplePhotosFolder + TestPhotos.UnitTestTemp1)) { File.Delete(this.samplePhotosFolder + TestPhotos.UnitTestTemp1); } }
public static void ReadWLPGRegions(string inputFile) { using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile)) { // Declare a bunch of XMP paths (see my last blog for details) string microsoftRegions = @"/xmp/MP:RegionInfo/MPRI:Regions"; string microsoftPersonDisplayName = @"/MPReg:PersonDisplayName"; string microsoftRectangle = @"/MPReg:Rectangle"; // Check there is a RegionInfo if (wpfFileManager.BitmapMetadata.ContainsQuery(microsoftRegions)) { BitmapMetadata regionsMetadata = wpfFileManager.BitmapMetadata.GetQuery(microsoftRegions) as BitmapMetadata; // Loop through each Region foreach (string regionQuery in regionsMetadata) { string regionFullQuery = microsoftRegions + regionQuery; // Query for all the data for this region BitmapMetadata regionMetadata = wpfFileManager.BitmapMetadata.GetQuery(regionFullQuery) as BitmapMetadata; if (regionMetadata != null) { if (regionMetadata.ContainsQuery(microsoftPersonDisplayName)) { Console.WriteLine("PersonDisplayName:\t" + regionMetadata.GetQuery(XmpMicrosoftQueries.RegionPersonDisplayName.Query).ToString()); } if (regionMetadata.ContainsQuery(microsoftRectangle)) { Console.WriteLine("Rectangle:\t\t" + regionMetadata.GetQuery(XmpMicrosoftQueries.RegionRectangle.Query).ToString()); } } } } } }
public static void RemoveIPTCAddres(string inputFile) { File.Copy(inputFile, "BitmapMetadataExamples.RemoveIPTCAddres.jpg", true); // Queries for the IPTC Address fields // Note: Region is normally the State or County string iptcCountry = @"/app13/irb/8bimiptc/iptc/Country\/Primary Location Name"; string iptcRegion = @"/app13/irb/8bimiptc/iptc/Province\/State"; string iptcCity = @"/app13/irb/8bimiptc/iptc/City"; string iptcSubLocation = @"/app13/irb/8bimiptc/iptc/Sub-location"; using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile, true)) { // Remove IPTC Address fields wpfFileManager.BitmapMetadata.RemoveQuery(iptcCity); wpfFileManager.BitmapMetadata.RemoveQuery(iptcCountry); wpfFileManager.BitmapMetadata.RemoveQuery(iptcRegion); wpfFileManager.BitmapMetadata.RemoveQuery(iptcSubLocation); wpfFileManager.WriteMetadata(); } }
public static void ReadGpsLatitude(string inputFile) { using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile)) { // Grab the GpsLatitudeRef // 'N' indicates north latitude, and 'S' is south latitude string latitudeRef = wpfFileManager.BitmapMetadata.GetQuery("/app1/ifd/Gps/subifd:{uint=1}").ToString(); // Grab GpsLatitude as a ulong array ulong[] rational = (ulong[])wpfFileManager.BitmapMetadata.GetQuery("/app1/ifd/Gps/subifd:{uint=2}"); double[] latitude = new double[3]; // Read and convert each of the rationals into a double for (int i = 0; i < 3; i++) { // Now shift & mask out the upper and lower parts to get the numerator and the denominator uint numerator = (uint)(rational[i] & 0xFFFFFFFFL); uint denominator = (uint)((rational[i] & 0xFFFFFFFF00000000L) >> 32); latitude[i] = Math.Round(Convert.ToDouble(numerator) / Convert.ToDouble(denominator), 3); } } }
public void ReadPadding() { // Load a file with default padding set using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.UnitTest1)) { // Check Padding Amounts Assert.AreEqual <UInt32>(wpfFileManager.BitmapMetadata.GetQuery <UInt32>(ExifQueries.Padding.Query), 5120, "UnitTest1.Exif Padding"); Assert.AreEqual <UInt32>(wpfFileManager.BitmapMetadata.GetQuery <UInt32>(IptcQueries.Padding.Query), 5120, "UnitTest1.Iptc Padding"); // Don't understand why this is 0, it should be 5120 Assert.AreEqual <UInt32>(wpfFileManager.BitmapMetadata.GetQuery <UInt32>(XmpCoreQueries.Padding.Query), 0); } // Load a file with no padding set using (WpfFileManager wpfFileManager = new WpfFileManager(this.samplePhotosFolder + TestPhotos.UnitTest2)) { // Check Padding Amounts Assert.AreEqual <UInt32>(wpfFileManager.BitmapMetadata.GetQuery <UInt32>(ExifQueries.Padding.Query), 5120, "UnitTest2.Exif Padding"); Assert.AreEqual <object>(wpfFileManager.BitmapMetadata.GetQuery(XmpCoreQueries.Padding.Query), null, "UnitTest2.Xmp Padding"); Assert.AreEqual <UInt32>(wpfFileManager.BitmapMetadata.GetQuery <UInt32>(IptcQueries.Padding.Query), 5120, "UnitTest2.Iptc Padding"); } }
public static void CreateWLPGRegions(string inputFile) { using (WpfFileManager wpfFileManager = new WpfFileManager(inputFile, true)) { // Declare a bunch of XMP paths (see my last blog for details) string microsoftRegionInfo = @"/xmp/MP:RegionInfo"; string microsoftRegions = @"/xmp/MP:RegionInfo/MPRI:Regions"; string microsoftPersonDisplayName = @"/MPReg:PersonDisplayName"; wpfFileManager.BitmapMetadata.SetQuery(microsoftRegionInfo, new BitmapMetadata("xmpstruct")); wpfFileManager.BitmapMetadata.SetQuery(microsoftRegions, new BitmapMetadata("xmpbag")); wpfFileManager.BitmapMetadata.SetQuery(microsoftRegions + "/{ulong=0}", new BitmapMetadata("xmpstruct")); wpfFileManager.BitmapMetadata.SetQuery(microsoftRegions + "/{ulong=0}" + microsoftPersonDisplayName, "Test " + DateTime.Now.ToString()); wpfFileManager.BitmapMetadata.SetQuery(microsoftRegions + "/{ulong=1}", new BitmapMetadata("xmpstruct")); wpfFileManager.BitmapMetadata.SetQuery(microsoftRegions + "/{ulong=1}" + microsoftPersonDisplayName, "Test " + DateTime.Now.ToString()); wpfFileManager.WriteMetadata(); } }
public void MetadataFromImage(string image) { JpgPhoto mainPhoto = new JpgPhoto(image); _mainPictureFilename = image; _lat=mainPhoto.Metadata.GpsPositionOfLocationCreated.Latitude.Numeric; _lon=mainPhoto.Metadata.GpsPositionOfLocationCreated.Longitude.Numeric; _alt=mainPhoto.Metadata.GpsPositionOfLocationCreated.Altitude; //TODO: We need a Fotofly method for retrieving the compass metadata. //No standard in JpgPhoto class. We add references to PresentationCore and WindowsBase //from .NET 3.0 WpfFileManager wpf = new WpfFileManager(image, false); URational urational = wpf.BitmapMetadata.GetQuery<URational>(GpsQueries.ImgDirection.Query); _compass=urational.ToDouble(3); }