Exemple #1
0
        /// <summary>
        /// Gets the GPS time offset from EXIF timestamp
        /// assumes no camera date set 10years in future, but may be 10years behind if reset to default
        /// </summary>
        /// <param name="filename"></param>
        /// <returns>
        ///     float to 0.05 hr  +12 -> -12 valid, 99999 not an image, 99901 no GPS time
        ///     camera name
        /// </returns>

        public static CameraTimeOffset GetEXIFtime_diff(string filename)
        {
            Exif_Ext.EXIF_Data exif_Data = new Exif_Ext.EXIF_Data(filename);

            switch (exif_Data.Status)
            {
            case "ok":
                if (exif_Data.CameraName is null)
                {
                    exif_Data.CameraName = "---";
                }
                if (exif_Data.GPSUTCDate == DateTime.MinValue)
                {
                    return(new CameraTimeOffset(exif_Data.CameraName, 99901));
                }

                DateTime localGPStime = GPSMethods.GetLocalTimefromGPS(exif_Data.GPSLatitude, exif_Data.GPSLongitude, exif_Data.GPSUTCDate);

                TimeSpan lastCameraOffset = exif_Data.CameraDate.Subtract(localGPStime);

                //float timedif = (float)Math.Round(lastCameraOffset.TotalHours,1);
                double           roundto    = 0.05;
                float            timedif    = (float)(Math.Ceiling(lastCameraOffset.TotalHours / roundto) * roundto);
                CameraTimeOffset thisOffset = new CameraTimeOffset(exif_Data.CameraName, -1 * timedif);
                return(thisOffset);

            case "Not Image":
                return(new CameraTimeOffset("Not Image", 99999));

            default:
                //error occurred
                return(new CameraTimeOffset("Exception", 99999));
            }
        }
Exemple #2
0
        private void Makelist(DirectoryInfo di)
        {
            RaiseProgress("Creating image list..", 10);
            FileInfo[] availFiles = di.GetFiles();
            int        maxFiles   = availFiles.Length;
            int        filenum    = 0;

            #region make the list
            foreach (FileInfo thisPhotoFile in di.GetFiles())
            {
                filenum++;
                int percentdone = Convert.ToInt32(filenum * 100.0 / maxFiles);
                if (filenum % 5 == 0)
                {
                    RaiseProgress(string.Format("processing image #{0}", filenum), Convert.ToInt32(10 + percentdone / 2));
                }

                PhotoDetail thisPhoto = new PhotoDetail
                {
                    latitude = -99 //cant be plotted
                };
                //test if it is a valid image
                switch (thisPhotoFile.Extension.ToUpper())
                {
                case ".JPG":
                case ".JPEG":
                case ".TIFF":

                    thisPhoto.Description = thisPhotoFile.Name;

                    Exif_Ext.EXIF_Data exif = new Exif_Ext.EXIF_Data(thisPhotoFile.FullName);

                    DateTime dateTaken = exif.CameraDate;

                    if (exif.GPSLatitude == 0)
                    {
                        break;
                    }
                    if (exif.GPSLatitude == -999)
                    {
                        break;
                    }
                    //if(exif.GPSUTCDate > DateTime.MinValue && UseGPSDate)
                    //{
                    //    dateTaken = GPSMethods.GetLocalTimefromGPS(exif.GPSLatitude, exif.GPSLongitude, exif.GPSUTCDate);
                    //}
                    thisPhoto.latitude  = exif.GPSLatitude;
                    thisPhoto.longitude = exif.GPSLongitude;


                    thisPhoto.DateTaken = dateTaken;

                    if (SortByDateTaken)
                    {
                        thisPhoto.keyid = thisPhoto.DateTaken.ToString("yyyyMMdd-HHmmss");
                    }
                    else
                    {
                        thisPhoto.keyid = thisPhoto.Description;
                    }

                    break;

                default:
                    //ignore unsupperted files
                    break;
                }

                //now attempt to load to the list. may generate duplicate key.
                int    retry         = 0;
                string originalkeyid = thisPhoto.keyid;

                if (thisPhoto.latitude > -99)
                {
                    do
                    {
                        if (retry > 0)
                        {
                            thisPhoto.keyid = string.Format("{0}{1:00}", originalkeyid, retry);
                        }
                        thisPhoto.ThumbnailFilename = Path.Combine(thumbFolder, thisPhoto.keyid + thisPhotoFile.Extension);
                        thisPhoto.ImageFilename     = Path.Combine(imageFolder, thisPhoto.keyid + thisPhotoFile.Extension);
                        try
                        {
                            //save the data to the Sorted list
                            inputPhotos.Add(thisPhoto.keyid, thisPhoto);
                            retry = 0;
                        }
                        catch (ArgumentException)
                        {
                            retry++;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            throw;
                        }
                    } while (retry > 0);

                    //now have unique id, create the smaller images and thumbnails
                    ResizeImages(thisPhotoFile, thisPhoto);
                }
            }

            #endregion
        }