示例#1
0
        public void ReadCameraMake()
        {
            // Read photos from a couple of different cameras, the aim is to ensure no exception is thrown reading the data
            JpgPhoto photo = TestPhotos.Load(TestPhotos.MakeKodakDX4900);

            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakeNikonCoolPixP80);
            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakeNikonD70);
            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakePentaxOptioS);
            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakeSonyDSCT30);
            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakeiPhone3GsUntouched);
            photo.ReadMetadata();

            Assert.AreEqual <string>(photo.Metadata.CameraManufacturer, "Apple", "CameraManufacturer");
            Assert.AreEqual <string>(photo.Metadata.CameraModel, "iPhone 3GS", "CameraModel");
            Assert.AreEqual <DateTime>(photo.Metadata.DateDigitised, new DateTime(2010, 02, 01, 08, 24, 40), "DateDigitised");
            Assert.AreEqual <MetadataEnums.MeteringModes>(photo.Metadata.MeteringMode, MetadataEnums.MeteringModes.Average, "MeteringMode");
            Assert.AreEqual <string>(photo.Metadata.Aperture.ToString(), "f/2.8", "Aperture");
            Assert.AreEqual <string>(photo.Metadata.ShutterSpeed.ToString(), "1/170 sec.", "ShutterSpeed");

            photo = TestPhotos.Load(TestPhotos.MakeiPhone3GsWithTags);
            photo.ReadMetadata();

            Assert.AreEqual <Tag>(photo.Metadata.Tags.First(), new Tag("Test"), "Tag");
        }
示例#2
0
        public void WriteImageRegionMetadata()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp4);

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            string testValueSuffix = DateTime.Now.ToUniversalTime().ToString();

            testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonDisplayName = "PersonDisplayName" + testValueSuffix;
            testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonEmailDigest = "PersonEmailDigest" + testValueSuffix;
            testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonLiveIdCID   = "PersonLiveIdCID" + testValueSuffix;
            testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].RectangleString   = "0.1, 0.2, 0.3, 0.4";

            // And save
            testPhoto.WriteMetadata();

            // Now read it from scratch
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp4);

            StringAssert.Matches(testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonDisplayName, new Regex("PersonDisplayName" + testValueSuffix));
            StringAssert.Matches(testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonEmailDigest, new Regex("PersonEmailDigest" + testValueSuffix));
            StringAssert.Matches(testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonLiveIdCID, new Regex("PersonLiveIdCID" + testValueSuffix));
            StringAssert.Matches(testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].RectangleString, new Regex("0.1, 0.2, 0.3, 0.4"));

            File.Delete(testPhoto.FileFullName);
        }
示例#3
0
        public void ReadShuttersSpeedProperties()
        {
            JpgPhoto shutterSpeed10Seconds = TestPhotos.Load(TestPhotos.ShutterSpeed10Seconds);
            JpgPhoto shutterSpeed1Over10   = TestPhotos.Load(TestPhotos.ShutterSpeed1Over10);
            JpgPhoto shutterSpeed1Over1000 = TestPhotos.Load(TestPhotos.ShutterSpeed1Over1000);
            JpgPhoto shutterSpeed1Over2    = TestPhotos.Load(TestPhotos.ShutterSpeed1Over2);
            JpgPhoto shutterSpeed1Over285  = TestPhotos.Load(TestPhotos.ShutterSpeed1Over285);
            JpgPhoto shutterSpeed1Over60   = TestPhotos.Load(TestPhotos.ShutterSpeed1Over60);
            JpgPhoto shutterSpeed2Seconds5 = TestPhotos.Load(TestPhotos.ShutterSpeed2Seconds5);

            // Read as Property
            Assert.AreEqual <ShutterSpeed>(shutterSpeed10Seconds.Metadata.ShutterSpeed, new ShutterSpeed(10), "ShutterSpeed 10 secs As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over10.Metadata.ShutterSpeed, new ShutterSpeed(0.1), "ShutterSpeed 1/10 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over1000.Metadata.ShutterSpeed, new ShutterSpeed(0.001), "ShutterSpeed 1/1000 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over2.Metadata.ShutterSpeed, new ShutterSpeed(0.5), "ShutterSpeed 1/2 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over285.Metadata.ShutterSpeed, new ShutterSpeed(0.003509), "ShutterSpeed 1/285 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over60.Metadata.ShutterSpeed, new ShutterSpeed(0.016667), "ShutterSpeed 1/60 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed2Seconds5.Metadata.ShutterSpeed, new ShutterSpeed(2.5), "ShutterSpeed 2.5 secs As Property");

            // Read as String
            Assert.AreEqual <string>(shutterSpeed10Seconds.Metadata.ShutterSpeed.ToString(), "10 sec.", "ShutterSpeed 10 secs As String");
            Assert.AreEqual <string>(shutterSpeed1Over10.Metadata.ShutterSpeed.ToString(), "1/10 sec.", "ShutterSpeed 1/10 As String");
            Assert.AreEqual <string>(shutterSpeed1Over1000.Metadata.ShutterSpeed.ToString(), "1/1000 sec.", "ShutterSpeed 1/1000 As String");
            Assert.AreEqual <string>(shutterSpeed1Over2.Metadata.ShutterSpeed.ToString(), "1/2 sec.", "ShutterSpeed 1/2 As String");
            Assert.AreEqual <string>(shutterSpeed1Over285.Metadata.ShutterSpeed.ToString(), "1/285 sec.", "ShutterSpeed 1/285 As String");
            Assert.AreEqual <string>(shutterSpeed1Over60.Metadata.ShutterSpeed.ToString(), "1/60 sec.", "ShutterSpeed 1/60 As String");
            Assert.AreEqual <string>(shutterSpeed2Seconds5.Metadata.ShutterSpeed.ToString(), "2.5 sec.", "ShutterSpeed 2.5 secs As String");
        }
示例#4
0
		public Sample(double lat, double lon, string image)
		{
			_lat=lat;
			_lon=lon;
			_imageName=image;
			
			JpgPhoto photo = new JpgPhoto(image);
			_cameraModel=photo.Metadata.CameraModel;
			_cameraManufacturer=photo.Metadata.CameraManufacturer;
			_height=photo.Metadata.ImageHeight;
			_width=photo.Metadata.ImageWidth;
			_verticalResolution=photo.Metadata.VerticalResolution;
			_horizontalResolution=photo.Metadata.HorizontalResolution;
			_dateTime=photo.Metadata.DateTaken;
			
			Analysis.SunriseSunsetCalculations isDay=new Analysis.SunriseSunsetCalculations(_dateTime,lat,lon);
			_dayOrNight=isDay.IsDay;
			
			Analysis.MoonPhaseCalculations moon= new Analysis.MoonPhaseCalculations(_dateTime.ToUniversalTime() );
			_moonPhase=moon.MoonPhase;
//			_cameraFlash=photo.Metadata.f
			
//			_idBase64picture = ImageProcessing.ImageUtilities.ImageToBase64( Image.FromFile(image),System.Drawing.Imaging.ImageFormat.Jpeg);
			
		}
示例#5
0
        public Sample(double lat, double lon, string image)
        {
            _lat       = lat;
            _lon       = lon;
            _imageName = image;

            JpgPhoto photo = new JpgPhoto(image);

            _cameraModel        = photo.Metadata.CameraModel;
            _cameraManufacturer = photo.Metadata.CameraManufacturer;
            _height             = photo.Metadata.ImageHeight;
            _width = photo.Metadata.ImageWidth;
            _verticalResolution   = photo.Metadata.VerticalResolution;
            _horizontalResolution = photo.Metadata.HorizontalResolution;
            _dateTime             = photo.Metadata.DateTaken;

            Analysis.SunriseSunsetCalculations isDay = new Analysis.SunriseSunsetCalculations(_dateTime, lat, lon);
            _dayOrNight = isDay.IsDay;

            Analysis.MoonPhaseCalculations moon = new Analysis.MoonPhaseCalculations(_dateTime.ToUniversalTime());
            _moonPhase = moon.MoonPhase;
//			_cameraFlash=photo.Metadata.f

//			_idBase64picture = ImageProcessing.ImageUtilities.ImageToBase64( Image.FromFile(image),System.Drawing.Imaging.ImageFormat.Jpeg);
        }
示例#6
0
        public static void ReadMetadata(string inputFile)
        {
            JpgPhoto jpgPhoto = new JpgPhoto(inputFile);

            jpgPhoto.ReadMetadata();

            Debug.WriteLine(jpgPhoto.Metadata.CameraModel);
        }
示例#7
0
        public static void GenerateFileNames(string inputFile)
        {
            // Read File
            JpgPhoto jpgphoto = new JpgPhoto(inputFile);

            jpgphoto.ReadMetadata();

            // Write out three suggested file names
            Console.WriteLine(jpgphoto.RecommendedFileName(GenericPhotoEnums.FilenameFormats.yyyymmddSecondsSinceMidnight, "Photo"));
            Console.WriteLine(jpgphoto.RecommendedFileName(GenericPhotoEnums.FilenameFormats.yyyymmddHoursMinutesSeconds, "Photo"));
            Console.WriteLine(jpgphoto.RecommendedFileName(GenericPhotoEnums.FilenameFormats.yyyymmddSequence, "Photo"));
        }
示例#8
0
        public static void AddTag(string inputFile)
        {
            File.Copy(inputFile, "JpgPhotoExamples.AddTag.jpg", true);

            JpgPhoto jpgPhoto = new JpgPhoto("JpgPhotoExamples.AddTag.jpg");

            jpgPhoto.ReadMetadata();

            jpgPhoto.Metadata.Tags.Add("Test Tag: " + DateTime.Now.ToString());

            jpgPhoto.WriteMetadata();
        }
示例#9
0
        public static void WriteMetadata(string inputFile)
        {
            File.Copy(inputFile, "JpgPhotoExamples.WriteMetadata.jpg", true);

            JpgPhoto jpgPhoto = new JpgPhoto("JpgPhotoExamples.WriteMetadata.jpg");

            jpgPhoto.ReadMetadata();

            jpgPhoto.Metadata.Comment = "Test Comment";

            jpgPhoto.WriteMetadata();
        }
示例#10
0
        public void ReadExposureBias()
        {
            // 0
            Assert.AreEqual <ExposureBias>(this.jpgPhotoOne.Metadata.ExposureBias, new ExposureBias());

            // -1.3 step
            JpgPhoto jpgPhoto = TestPhotos.Load(TestPhotos.ExposureBiasMinus13);

            Assert.AreEqual <ExposureBias>(jpgPhoto.Metadata.ExposureBias, new ExposureBias("-4/3"));

            // +1.3 step
            jpgPhoto = TestPhotos.Load(TestPhotos.ExposureBiasPlus13);
            Assert.AreEqual <ExposureBias>(jpgPhoto.Metadata.ExposureBias, new ExposureBias("4/3"));
        }
示例#11
0
        //public void FindGpsPositionShown(JpgPhoto photo, bool reparse)
        //{
        //    // Reset Data
        //    if (reparse)
        //    {
        //        photo.Metadata.GpsPositionOfLocationShown = new GpsPosition();
        //    }

        //    // If we have no valid result try alternate methods
        //    if (!photo.Metadata.GpsPositionOfLocationShown.IsValidCoordinate)
        //    {
        //        // Retrieve result from Bing & Cache and choose the most accurate
        //        GpsPosition bingResult = new GpsPosition();
        //        int bingAccuracy = 0;
        //        GpsPosition manualResult = new GpsPosition();
        //        int manualAccuracy = 0;

        //        // Use Bing if Configured
        //        if (this.IsBingMapsResolverConfigured)
        //        {
        //            // Check Bing
        //            // Cycle through the address, start as accurate as possible
        //            for (int i = photo.Metadata.AddressOfLocationShown.HierarchicalNameLength; i > 0; i--)
        //            {
        //                // Query Bing
        //                bingResult = this.bingMapsResolver.FindGpsPosition(photo.Metadata.AddressOfLocationShown.AddressTruncated(i));

        //                if (bingResult != null && bingResult.IsValidCoordinate)
        //                {
        //                    bingAccuracy = i;
        //                    break;
        //                }
        //                else
        //                {
        //                    bingResult = new GpsPosition();
        //                }
        //            }
        //        }

        //        // Use Cache if Configured
        //        if (this.IsManualCacheConfigured)
        //        {
        //            // Check Cache
        //            // Cycle through the address, start as accurate as possible
        //            for (int i = photo.Metadata.AddressOfLocationShown.HierarchicalNameLength; i > 0; i--)
        //            {
        //                // Query Cache
        //                manualResult = this.manualCache.FindGpsPosition(photo.Metadata.AddressOfLocationShown.AddressTruncated(i));

        //                if (manualResult != null && manualResult.IsValidCoordinate)
        //                {
        //                    manualAccuracy = i;
        //                    break;
        //                }
        //                else
        //                {
        //                    manualResult = new GpsPosition();
        //                }
        //            }
        //        }

        //        if (manualAccuracy == 0 && bingAccuracy == 0)
        //        {
        //            photo.Metadata.GpsPositionOfLocationShown = new GpsPosition();
        //        }
        //        else if (manualAccuracy > bingAccuracy)
        //        {
        //            photo.Metadata.GpsPositionOfLocationShown = manualResult;
        //            photo.Metadata.GpsPositionOfLocationShown.Time = new DateTime();
        //        }
        //        else
        //        {
        //            photo.Metadata.GpsPositionOfLocationShown = bingResult;
        //            photo.Metadata.GpsPositionOfLocationShown.Time = new DateTime();
        //        }
        //    }
        //}

        public void FindAddressCreated(JpgPhoto photo, bool reparse)
        {
            // Look up address for Gps Position recorded by a Tracker
            // Gps Location Created must be valid
            if (photo.Metadata.GpsPositionOfLocationCreated.IsValidCoordinate)
            {
                // Order is: 1) Bing Maps 2) Google Maps

                // Save the current address, or reset it
                Address newAddress = reparse == true ? new Address() : photo.Metadata.AddressOfLocationCreated;

                // Use Bing if configured
                //if (!newAddress.IsValidAddress && this.IsBingMapsResolverConfigured)
                //{
                //    Address bingAddress = this.bingMapsResolver.FindAddress(photo.Metadata.GpsPositionOfLocationCreated, photo.Metadata.AddressOfLocationShown.Country);

                //    if (bingAddress.IsValidAddress && !bingAddress.Equals(photo.Metadata.AddressOfLocationCreated))
                //    {
                //        photo.Metadata.AddressOfLocationCreated = bingAddress;
                //        photo.Metadata.AddressOfLocationCreatedLookupDate = DateTime.Now;
                //        photo.Metadata.AddressOfLocationCreatedSource = BingMapsResolver.SourceName;

                //        newAddress = bingAddress;
                //    }
                //}

                // Use Google if configured
                if (!newAddress.IsValidAddress && this.IsGoogleMapsResolverConfigured)
                {
                    Address googleAddress = this.googleMapsResolver.FindAddress(photo.Metadata.GpsPositionOfLocationCreated);

                    if (googleAddress.IsValidAddress && !googleAddress.Equals(photo.Metadata.AddressOfLocationCreated))
                    {
                        photo.Metadata.AddressOfLocationCreated           = googleAddress;
                        photo.Metadata.AddressOfLocationCreatedLookupDate = DateTime.Now;
                        photo.Metadata.AddressOfLocationCreatedSource     = GoogleMapsResolver.SourceName;

                        newAddress = googleAddress;
                    }
                }

                if (!newAddress.IsValidAddress && !photo.Metadata.AddressOfLocationCreated.IsValidAddress)
                {
                    photo.Metadata.AddressOfLocationCreated           = new Address();
                    photo.Metadata.AddressOfLocationCreatedLookupDate = new DateTime();
                    photo.Metadata.AddressOfLocationCreatedSource     = null;
                }
            }
        }
示例#12
0
        public static void AddGpsCoor(string inputFile)
        {
            File.Copy(inputFile, "JpgPhotoExamples.AddGpsCoor.jpg", true);

            JpgPhoto jpgPhoto = new JpgPhoto("JpgPhotoExamples.AddGpsCoor.jpg");

            jpgPhoto.ReadMetadata();

            jpgPhoto.Metadata.GpsPositionOfLocationCreated.Latitude.Numeric  = 1.05;
            jpgPhoto.Metadata.GpsPositionOfLocationCreated.Longitude.Numeric = -0.95;
            jpgPhoto.Metadata.GpsPositionOfLocationCreated.Dimension         = GpsPosition.Dimensions.TwoDimensional;
            jpgPhoto.Metadata.GpsPositionOfLocationCreated.Source            = "GPS Test";

            jpgPhoto.WriteMetadata();
        }
示例#13
0
        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);
        }
示例#14
0
        public void ReadApertureProperties()
        {
            JpgPhoto aperture28 = TestPhotos.Load(TestPhotos.Aperture28);
            JpgPhoto aperture71 = TestPhotos.Load(TestPhotos.Aperture71);
            JpgPhoto aperture80 = TestPhotos.Load(TestPhotos.Aperture80);

            // Read as Property
            Assert.AreEqual <Aperture>(aperture28.Metadata.Aperture, new Aperture(2.8), "Aperture28 As Property");
            Assert.AreEqual <Aperture>(aperture71.Metadata.Aperture, new Aperture(7.1), "Aperture71 As Property");
            Assert.AreEqual <Aperture>(aperture80.Metadata.Aperture, new Aperture(8.0), "Aperture80 As Property");

            // Read as String
            Assert.AreEqual <string>(aperture28.Metadata.Aperture.ToString(), "f/2.8", "Aperture28 As String");
            Assert.AreEqual <string>(aperture71.Metadata.Aperture.ToString(), "f/7.1", "Aperture71 As String");
            Assert.AreEqual <string>(aperture80.Metadata.Aperture.ToString(), "f/8", "Aperture80 As String");
        }
示例#15
0
        public void BulkRead()
        {
            foreach (string file in Directory.GetFiles(TestPhotos.PhotosFolder, "*,jpg"))
            {
                JpgPhoto jpgPhoto = new JpgPhoto(file);

                try
                {
                    jpgPhoto.ReadMetadata();
                }
                catch
                {
                    Assert.Fail("Unable to read Metadata: " + file);
                }
            }
        }
        public static void SetPhotoTags(string inputFile, List <string> tags)
        {
            JpgPhoto jpgPhoto = new JpgPhoto(inputFile);

            // TODO:  BUGBUG:  Changing description is throwing exception. In the end it is trying to set null value
            //jpgPhoto.Metadata.Description = @"Tags updated on " + DateTime.Now.ToString();

            Console.WriteLine($"oldTags: {jpgPhoto.Metadata.Tags}");

            // not sure whether or not to preserve the old tags.
            // Assuming we are not settings the same tags repeatedly, retaining original tags.
            //jpgPhoto.Metadata.Tags.Clear();

            jpgPhoto.Metadata.Tags.AddRange(tags);
            jpgPhoto.WriteMetadata();
        }
示例#17
0
        public void WriteGpsMetadata()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            // Test data, includes Unicode strings
            GpsPosition positionCreated = new GpsPosition(101.23, -34.321, -99.8);
            GpsPosition positionShow    = new GpsPosition(-123.0, 179);

            // Scrub existing data
            testPhoto.Metadata.GpsPositionOfLocationCreated = new GpsPosition();
            testPhoto.Metadata.GpsPositionOfLocationShown   = new GpsPosition();
            testPhoto.WriteMetadata();

            // Check for empty data
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, new GpsPosition(), "Blank GpsPosition Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, new GpsPosition(), "Blank GpsPosition Shown");

            // Write GpsPosition Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            testPhoto.Metadata.GpsPositionOfLocationCreated = positionCreated;
            testPhoto.Metadata.GpsPositionOfLocationShown   = new GpsPosition();
            testPhoto.WriteMetadata();

            // And Check Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, positionCreated, "WriteCreated Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, new GpsPosition(), "WriteCreated Shown");

            // Write GpsPosition Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            testPhoto.Metadata.GpsPositionOfLocationCreated = new GpsPosition();
            testPhoto.Metadata.GpsPositionOfLocationShown   = positionShow;
            testPhoto.WriteMetadata();

            // And Check Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, new GpsPosition(), "WriteShown Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, positionShow, "WriteShown Shown");

            // Tidy up
            File.Delete(testPhoto.FileFullName);
        }
示例#18
0
        public void WriteAddressMetadata()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            // Test data, includes Unicode strings
            Address addressCreated = new Address(@"CòuntryCreàted/RegÎon/Ĉity/Stréét");
            Address addressShown   = new Address(@"CòuntryShówn/RegÎon/Ĉity/Stréét");

            // Scrub existing data
            testPhoto.Metadata.AddressOfLocationCreated = new Address();
            testPhoto.Metadata.AddressOfLocationShown   = new Address();
            testPhoto.WriteMetadata();

            // Check for empty data
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationCreated, new Address(), "Blank Address Created");
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationShown, new Address(), "Blank Address Shown");

            // Write Address Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);
            testPhoto.Metadata.AddressOfLocationCreated = addressCreated;
            testPhoto.Metadata.AddressOfLocationShown   = new Address();
            testPhoto.WriteMetadata();

            // And Check Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationCreated, addressCreated, "WriteAddress Created");
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationShown, new Address(), "WriteAddress Shown");

            // Write Address Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);
            testPhoto.Metadata.AddressOfLocationCreated = new Address();
            testPhoto.Metadata.AddressOfLocationShown   = addressShown;
            testPhoto.WriteMetadata();

            // And Check Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationCreated, new Address(), "WriteShown Created");
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationShown, addressShown, "WriteShown Shown");

            // Tidy up
            File.Delete(testPhoto.FileFullName);
        }
示例#19
0
        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);
        }
示例#20
0
 public static string ReadMetadata(string filename)
 {
     try
     {
         JpgPhoto image = new JpgPhoto(filename);
         image.ReadMetadata();
         ReadOnlyCollection <string> tag = image.Metadata.Tags.ToReadOnlyCollection();
         SD.Garbage.ClearRAM.Clear();
         string tags = "";
         foreach (string s in tag)
         {
             tags += s + ";";
         }
         return(tags);
     }
     catch
     {
         return("");
     }
 }
示例#21
0
        public static void AddRegion(string inputFile)
        {
            File.Copy(inputFile, "JpgPhotoExamples.AddRegion.jpg", true);

            // Open file and read metadata
            JpgPhoto jpgPhoto = new JpgPhoto("JpgPhotoExamples.AddRegion.jpg");

            jpgPhoto.ReadMetadata();

            // Create new Region
            MicrosoftImageRegion newRegion = new MicrosoftImageRegion();

            newRegion.PersonDisplayName = "Ben Vincent";
            newRegion.RectangleString   = "0.1, 0.1, 0.1, 0.1";

            // Add the new region to the photo
            jpgPhoto.Metadata.MicrosoftRegionInfo.Regions.Add(newRegion);

            // Save
            jpgPhoto.WriteMetadata();
        }
示例#22
0
        public void FindGpsPositionCreated(JpgPhoto photo, bool reparse)
        {
            // Reset Data
            if (reparse)
            {
                photo.Metadata.GpsPositionOfLocationCreated = new GpsPosition();
            }

            // Use Gpx Tracks if Configured
            if (!photo.Metadata.GpsPositionOfLocationCreated.IsValidCoordinate && this.IsGpxTracksResolverConfigured)
            {
                if (photo.Metadata.DateUtc == null || photo.Metadata.DateUtc == new DateTime())
                {
                    throw new Exception("Metadata.UtcDate must be set Gps Tracks are UTC based");
                }

                GpsPosition gpsPosition = this.gpxTrackResolver.FindGpsPosition(photo.Metadata.DateUtc);

                if (gpsPosition != null && gpsPosition.IsValidCoordinate)
                {
                    photo.Metadata.GpsPositionOfLocationCreated = gpsPosition;
                }
            }

            // Use Nmea Tracks if Configured
            if (!photo.Metadata.GpsPositionOfLocationCreated.IsValidCoordinate && this.IsNmeaTracksResolverConfigured)
            {
                if (photo.Metadata.DateUtc == null || photo.Metadata.DateUtc == new DateTime())
                {
                    throw new Exception("Metadata.UtcDate must be set Gps Tracks are UTC based");
                }

                GpsPosition gpsPosition = this.nmeaTrackResolver.FindGpsPosition(photo.Metadata.DateUtc);

                if (gpsPosition != null && gpsPosition.IsValidCoordinate)
                {
                    photo.Metadata.GpsPositionOfLocationCreated = gpsPosition;
                }
            }
        }
示例#23
0
        public void WriteAndReadMetadataToXmlFile()
        {
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp8);
            string   xmlFile   = testPhoto.FileFullName.Replace(".jpg", ".xml");

            // Clean up from previous test
            if (File.Exists(xmlFile))
            {
                File.Delete(xmlFile);
            }

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            testPhoto.ReadMetadata();
            testPhoto.WriteMetadataToXml(xmlFile);

            if (!File.Exists(xmlFile))
            {
                Assert.Fail("Serialised File was not found: " + xmlFile);
            }

            JpgPhoto xmlPhoto = new JpgPhoto(testPhoto.FileFullName);

            xmlPhoto.ReadMetadataFromXml(xmlFile);

            List <CompareResult> changes = new List <CompareResult>();

            PhotoMetadataTools.CompareMetadata(testPhoto.Metadata, xmlPhoto.Metadata, ref changes);

            if (changes.Count > 0)
            {
                Assert.Fail("Serialised File was incompleted: " + changes[0]);
            }

            File.Delete(testPhoto.FileFullName);
            File.Delete(xmlFile);
        }
示例#24
0
        public static JpgPhoto Load(string name)
        {
            JpgPhoto jpgPhoto = new JpgPhoto(PhotosFolder + name);

            return(jpgPhoto);
        }
示例#25
0
		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);
		}
示例#26
0
        public void FindGpsPositionShown(JpgPhoto photo, bool reparse)
        {
            // Reset Data
            if (reparse)
            {
                photo.Metadata.GpsPositionOfLocationShown = new GpsPosition();
            }

            // If we have no valid result try alternate methods
            if (!photo.Metadata.GpsPositionOfLocationShown.IsValidCoordinate)
            {
                // Retrieve result from Bing & Cache and choose the most accurate
                GpsPosition bingResult     = new GpsPosition();
                int         bingAccuracy   = 0;
                GpsPosition manualResult   = new GpsPosition();
                int         manualAccuracy = 0;

                // Use Bing if Configured
                if (this.IsBingMapsResolverConfigured)
                {
                    // Check Bing
                    // Cycle through the address, start as accurate as possible
                    for (int i = photo.Metadata.AddressOfLocationShown.HierarchicalNameLength; i > 0; i--)
                    {
                        // Query Bing
                        bingResult = this.bingMapsResolver.FindGpsPosition(photo.Metadata.AddressOfLocationShown.AddressTruncated(i));

                        if (bingResult != null && bingResult.IsValidCoordinate)
                        {
                            bingAccuracy = i;
                            break;
                        }
                        else
                        {
                            bingResult = new GpsPosition();
                        }
                    }
                }

                // Use Cache if Configured
                if (this.IsManualCacheConfigured)
                {
                    // Check Cache
                    // Cycle through the address, start as accurate as possible
                    for (int i = photo.Metadata.AddressOfLocationShown.HierarchicalNameLength; i > 0; i--)
                    {
                        // Query Cache
                        manualResult = this.manualCache.FindGpsPosition(photo.Metadata.AddressOfLocationShown.AddressTruncated(i));

                        if (manualResult != null && manualResult.IsValidCoordinate)
                        {
                            manualAccuracy = i;
                            break;
                        }
                        else
                        {
                            manualResult = new GpsPosition();
                        }
                    }
                }

                if (manualAccuracy == 0 && bingAccuracy == 0)
                {
                    photo.Metadata.GpsPositionOfLocationShown = new GpsPosition();
                }
                else if (manualAccuracy > bingAccuracy)
                {
                    photo.Metadata.GpsPositionOfLocationShown      = manualResult;
                    photo.Metadata.GpsPositionOfLocationShown.Time = new DateTime();
                }
                else
                {
                    photo.Metadata.GpsPositionOfLocationShown      = bingResult;
                    photo.Metadata.GpsPositionOfLocationShown.Time = new DateTime();
                }
            }
        }
示例#27
0
        /// <summary>
        /// Load files in one Folder, then recurse on all contained folders
        /// </summary>
        /// <param name="root">Current Top Level Folder Name</param>
        private void MyLoLoadFolder(DirectoryInfo root)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;
            // First, process all the files directly under this folder
            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                // This code just writes out the message and continues to recurse.
                // You may decide to do something different here. For example, you
                // can try to elevate your privileges and access the file again.
                log.Add(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to MyLoLoadFolder().
                    try
                    {
                        if (fi.Extension == ".jpg" || fi.Extension == ".JPG")
                        {
                            Photo photo = new Photo();
                            Image.GetThumbnailImageAbort myCallback =
                            new Image.GetThumbnailImageAbort(ThumbnailCallback);
                            Bitmap image = new Bitmap(fi.FullName);
                            Image thumb = image.GetThumbnailImage(100, 100, myCallback, IntPtr.Zero);

                            ImageConverter converter = new ImageConverter();
                            photo.Thumbnail = (byte[])converter.ConvertTo(thumb, typeof(byte[]));

                            // This is for testing only - should switch to more reliable Hash such as SHA-256 or MD5
                            //long CRC = CalculateCRCForFile(fi.FullName);
                            photo.CRC = image.GetHashCode();
                            image.Dispose();

                            JpgPhoto photoJpg = new JpgPhoto(fi.FullName);

                            photo.Uri = fi.FullName;
                            photo.Aperture = photoJpg.Metadata.Aperture;
                            photo.Camera = photoJpg.Metadata.CameraModel;
                            photo.DateTaken = photoJpg.Metadata.DateTaken;
                            photo.PhotoIndexKind = _timeIndexKind;
                            DateTime dat = photoJpg.Metadata.DateTaken.Date;
                            TimeSpan tim = photoJpg.Metadata.DateTaken.TimeOfDay;
                            if (photoJpg.Metadata.GpsPosition.Latitude.IsValidCoordinate)
                            {
                                photo.GpsLat = photoJpg.Metadata.GpsPosition.Latitude.Numeric;
                            }
                            if (photoJpg.Metadata.GpsPosition.Longitude.IsValidCoordinate)
                            {
                                photo.GpsLong = photoJpg.Metadata.GpsPosition.Longitude.Numeric;
                            }
                            photo.Uuid = Guid.NewGuid();

                            //foreach (Tag tag in photo.Metadata.Tags)
                            //{
                            //    Console.WriteLine(tag.FullName);
                            //}
                            long photoId = _myLoStore.AddPhoto(_userId, photo);

                            _count++;

                            // TODO add code to write back GUID and Hash into photo metadata
                        }
                    }
                    catch (MyLoCRCException crcEx)
                    {
                        throw new MyLoException("CRC Calculation Error: Inner exception: " + crcEx);
                    }
                    catch (MyLoDataStoreException dsEx)
                    {
                        throw new MyLoException("DataStore Error: Inner exception: " + dsEx);
                    }
                    catch (Exception ex)
                    {
                        throw new MyLoException("File not Found: " + fi.FullName + " Inner exception: " + ex);
                    }
                    Debug.WriteLine(fi.FullName);
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    MyLoLoadFolder(dirInfo);
                }
            }
        }
示例#28
0
        public void WriteMetadataAndCheckForImageLoss()
        {
            // File that will be changed
            JpgPhoto beforePhoto = new JpgPhoto(TestPhotos.UnitTestTemp6);
            JpgPhoto afterPhoto  = new JpgPhoto(TestPhotos.UnitTestTemp7);

            // Get a copy of a file
            File.Copy(this.jpgPhotoOne.FileFullName, beforePhoto.FileFullName, true);
            File.Copy(this.jpgPhotoOne.FileFullName, afterPhoto.FileFullName, true);

            // Change some metadata
            afterPhoto.Metadata.Description = "Test Description" + DateTime.Now.ToString();
            afterPhoto.Metadata.Comment     = "Test Comment" + DateTime.Now.ToString();
            afterPhoto.Metadata.Copyright   = "Test Copyright" + DateTime.Now.ToString();
            afterPhoto.Metadata.Subject     = "Subject Copyright" + DateTime.Now.ToString();

            // Save as temp file
            afterPhoto.WriteMetadata();

            // Open Original File
            using (Stream beforeStream = File.Open(beforePhoto.FileFullName, FileMode.Open, FileAccess.Read))
            {
                // Open the Saved File
                using (Stream afterStream = File.Open(afterPhoto.FileFullName, FileMode.Open, FileAccess.Read))
                {
                    // Compare every pixel to ensure it has changed
                    BitmapSource beforeBitmap = BitmapDecoder.Create(beforeStream, BitmapCreateOptions.None, BitmapCacheOption.OnDemand).Frames[0];
                    BitmapSource afterBitmap  = BitmapDecoder.Create(afterStream, BitmapCreateOptions.None, BitmapCacheOption.OnDemand).Frames[0];

                    PixelFormat pf = PixelFormats.Bgra32;

                    FormatConvertedBitmap fcbOne = new FormatConvertedBitmap(beforeBitmap, pf, null, 0);
                    FormatConvertedBitmap fcbTwo = new FormatConvertedBitmap(afterBitmap, pf, null, 0);

                    GC.AddMemoryPressure(((fcbOne.Format.BitsPerPixel * (fcbOne.PixelWidth + 7)) / 8) * fcbOne.PixelHeight);
                    GC.AddMemoryPressure(((fcbTwo.Format.BitsPerPixel * (fcbTwo.PixelWidth + 7)) / 8) * fcbTwo.PixelHeight);

                    int width  = fcbOne.PixelWidth;
                    int height = fcbOne.PixelHeight;

                    int bpp    = pf.BitsPerPixel;
                    int stride = (bpp * (width + 7)) / 8;

                    byte[] scanline0 = new byte[stride];
                    byte[] scanline1 = new byte[stride];

                    Int32Rect lineRect = new Int32Rect(0, 0, width, 1);

                    // Loop through each row
                    for (int y = 0; y < height; y++)
                    {
                        lineRect.Y = y;

                        fcbOne.CopyPixels(lineRect, scanline0, stride, 0);
                        fcbTwo.CopyPixels(lineRect, scanline1, stride, 0);

                        // Loop through each column
                        for (int b = 0; b < stride; b++)
                        {
                            if (Math.Abs(scanline0[b] - scanline1[b]) > 0)
                            {
                                Assert.Fail("Saved file was not solved losslessly");
                            }
                        }
                    }
                }
            }

            // Tidy UP
            File.Delete(beforePhoto.FileFullName);
            File.Delete(afterPhoto.FileFullName);
        }
示例#29
0
 public JpgPhotoUnitTests()
 {
     this.jpgPhotoOne = TestPhotos.Load(TestPhotos.UnitTest1);
     this.jpgPhotoTwo = TestPhotos.Load(TestPhotos.UnitTest2);
 }
示例#30
0
        public void WriteMetadataToFile()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp3);

            File.Copy(this.jpgPhotoTwo.FileFullName, testPhoto.FileFullName, true);

            // Test value to write
            string   testString = "Test " + DateTime.Now.ToString();
            DateTime testDate   = DateTime.Now.AddTicks(-DateTime.Now.TimeOfDay.Ticks);
            string   testTag    = "Test Tag Î";

            // Write text
            testPhoto.Metadata.Description = testString;
            testPhoto.Metadata.Comment     = testString;
            testPhoto.Metadata.Copyright   = testString;
            testPhoto.Metadata.AddressOfLocationCreatedSource = testString;
            testPhoto.Metadata.Tags = new TagList();
            testPhoto.Metadata.Tags.Add(new Tag(testTag));

            // Write dates
            testPhoto.Metadata.DateAquired   = testDate;
            testPhoto.Metadata.DateDigitised = testDate;
            testPhoto.Metadata.DateTaken     = testDate;
            testPhoto.Metadata.DateUtc       = testDate;
            testPhoto.Metadata.AddressOfLocationCreatedLookupDate = testDate;

            // Save Photo Three
            testPhoto.WriteMetadata();

            // Check the file was created
            if (!File.Exists(testPhoto.FileFullName))
            {
                Assert.Fail("File save failed");
            }

            // Read metadata
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp3);
            testPhoto.ReadMetadata();

            // Check the file was created
            if (testPhoto.Metadata == null)
            {
                Assert.Fail("Unable to read saved files metadata");
            }

            // Check the text was set correctly
            StringAssert.Matches(testPhoto.Metadata.Description, new Regex(testString), "Description");
            StringAssert.Matches(testPhoto.Metadata.Comment, new Regex(testString), "Comment");
            StringAssert.Matches(testPhoto.Metadata.Copyright, new Regex(testString), "Copyright");
            StringAssert.Matches(testPhoto.Metadata.AddressOfLocationCreatedSource, new Regex(testString), "AddressOfLocationCreatedSource");

            // Check date was written
            Assert.AreEqual <DateTime>(testPhoto.Metadata.DateAquired, testDate, "DateAquired");
            Assert.AreEqual <DateTime>(testPhoto.Metadata.DateDigitised, testDate, "DateDigitised");
            Assert.AreEqual <DateTime>(testPhoto.Metadata.DateTaken, testDate, "DateTaken");
            Assert.AreEqual <DateTime>(testPhoto.Metadata.DateUtc, testDate, "UtcDate");
            Assert.AreEqual <DateTime>(testPhoto.Metadata.AddressOfLocationCreatedLookupDate, testDate, "AddressOfLocationCreatedLookupDate");
            Assert.AreEqual <Tag>(testPhoto.Metadata.Tags.Last(), new Tag(testTag), "Tags");

            if (new FileInfo(this.jpgPhotoTwo.FileFullName).Length > new FileInfo(testPhoto.FileFullName).Length)
            {
                Assert.Fail("Photo has decreased in size after saving");
            }

            File.Delete(testPhoto.FileFullName);
        }
示例#31
0
        private void GetMetaData(string path, Image image)
        {
            try
            {
                //var test = new JpgPhoto(@"C:\git\dev\SusannahStorchLLC\SusannahStorchLLC\SusannahStorchLLC\photos\Projects\bagpipes.jpg");
                //var te = test.Metadata.Title;

                var photo = new JpgPhoto(Path.Combine(path,  image.Category + "\\" + image.Path ));

                foreach (var tag in photo.Metadata.Tags)
                {
                    image.Tags.Add(tag.FullName);
                }

                image.Description = photo.Metadata.Comment;
                image.Title = photo.Metadata.Title;

                image.Orientation.Height = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get("imageheight"));
                var ratio = (decimal)photo.Metadata.ImageHeight / (decimal)photo.Metadata.ImageWidth;

                image.Orientation.Width =  (int)Math.Round( (decimal)image.Orientation.Height / ratio);

            }
            catch (Exception e)
            {
            }
        }