示例#1
0
        public static ImageHeaderInfo GetHeaderInfo(PropertyItem[] PropertyItems)
        {
            Encoding        enc        = Encoding.Default;
            ImageHeaderInfo headerInfo = new ImageHeaderInfo();

            foreach (PropertyItem Info in PropertyItems)
            {
                switch (Info.Id.ToString("X"))
                {
                case "9003":
                    headerInfo.captureDate = enc.GetString(Info.Value, 0, Info.Len - 1);
                    break;

                case "10F":
                    headerInfo.manufacturer = enc.GetString(Info.Value, 0, Info.Len - 1);
                    break;

                case "110":
                    headerInfo.model = enc.GetString(Info.Value, 0, Info.Len - 1);
                    break;
                }
            }

            return(headerInfo);
        }
示例#2
0
        public static void ChangeCaptureDateInFile(string fullFilename, LongTimeSpan timeDiff, string camerafilter = null)
        {
            string   capDate = "";
            Encoding enc     = Encoding.Default;
            DateTime datetime;


            Byte[] bytes = File.ReadAllBytes(fullFilename);
            using (MemoryStream stream = new MemoryStream(bytes))
                using (Image img = Image.FromStream(stream))
                {
                    if (camerafilter != null)
                    {
                        ImageHeaderInfo info = GetHeaderInfo(img.PropertyItems);
                        if (camerafilter != info.FullCameraName)
                        {
                            return;
                        }
                    }

                    foreach (PropertyItem Info in img.PropertyItems)
                    {
                        switch (Info.Id.ToString("X"))
                        {
                        case "110":
                            break;

                        case "9003":
                            capDate  = enc.GetString(Info.Value, 0, Info.Len - 1);
                            datetime = DateTime.ParseExact(capDate, "yyyy:MM:dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                            datetime = timeDiff.IncreaseDateTime(datetime);

                            List <byte> zero     = new List <byte>(new byte[] { 0 });
                            byte[]      newValue = enc.GetBytes(datetime.ToString("yyyy:MM:dd HH:mm:ss")).Concat(zero).ToArray();
                            Info.Value = newValue;
                            Info.Len   = newValue.Length;
                            img.SetPropertyItem(Info);
                            break;
                        }
                    }

                    img.Save(fullFilename);
                }
        }
示例#3
0
        public static List <PhotoInfo> GetPhotosFromDirectory(string directory, string filter = ".jpg|.jpeg", string camerafilter = null, BackgroundWorker worker = null, DoWorkEventArgs e = null)
        {
            List <PhotoInfo> photos = new List <PhotoInfo>();

            DirectoryInfo dirInfo = new DirectoryInfo(directory);

            FileInfo[] fileInfos = dirInfo.GetFiles();

            int progress = 0;

            foreach (var fileInfo in fileInfos)
            {
                if (ApplyFilter(fileInfo.Name, filter))
                {
                    ImageHeaderInfo headerInfo = GetHeaderInfo(fileInfo.FullName); //ImageHeaderInfo contains capture date of the picture
                    if (headerInfo.captureDate != "")
                    {
                        if (camerafilter == null || camerafilter == headerInfo.FullCameraName)
                        {
                            photos.Add(new PhotoInfo(fileInfo, headerInfo));
                        }
                    }
                }

                progress++;

                if (worker != null)
                {
                    if (worker.CancellationPending == true)
                    {
                        e.Cancel = true;
                        return(new List <PhotoInfo>());
                    }
                    else
                    {
                        worker.ReportProgress(50 * progress / fileInfos.Length);
                    }
                }
            }


            return(photos);
        }
示例#4
0
        public static string GetCaptureDate(string fullFilename)
        {
            ImageHeaderInfo headerInfo = GetHeaderInfo(fullFilename);

            return(headerInfo.captureDate);
        }