/// <summary> /// Gets the date the photo was taken. /// </summary> private void ReadDateTaken() { if (this.PhotoBitmap != null) { DateTime datetaken = DateTime.Now; Bitmap photo = this.PhotoBitmap; // Extract exif metadata ExifFile file = ExifFile.Read(this.FilePath); ExifProperty exifProperty = file.Properties[ExifTag.DateTime]; if (exifProperty != null) { try { datetaken = Convert.ToDateTime(exifProperty.Value); this.PhotoDateTime = datetaken; } catch { } } return; } else { throw new NullReferenceException(); } }
/// <summary> /// 获取视频或者图片的拍摄时间 /// </summary> /// <param name="file"></param> /// <param name="type">图片或视频</param> /// <returns></returns> static DateTime GetEncodedDate(string file, FileType type) { if (type == FileType.Video) { var mf = new MediaFile(file); return(mf.encodedDate); } else if (type == FileType.Image) { ExifFile data = ExifFile.Read(file); foreach (ExifProperty item in data.Properties.Values) { if (item.Tag == ExifTag.DateTimeOriginal) { return((DateTime)item.Value); } if (item.Tag == ExifTag.DateTimeDigitized) { return((DateTime)item.Value); } } return(DateTime.Now); } else { return(DateTime.Now); } }
private void SaveImageToCameraRoll(Stream stream, MemoryStream thumbStream) { string fileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff") + "#" + m_sequenceGuid.ToString(); ExifFile exif = ExifFile.ReadStream(stream); string metadata = GetMetadata(fileName); byte[] data = Encoding.UTF8.GetBytes(metadata); uint length = (uint)data.Length; ushort type = 2; var imgDescProp = ExifPropertyFactory.Get(0x010e, type, length, data, BitConverterEx.ByteOrder.BigEndian, IFD.Zeroth); exif.Properties.Add(ExifTag.ImageDescription, imgDescProp); using (var ml = new MediaLibrary()) { exif.SaveToCameraRoll("mapi_" + fileName + ".jpg", ml); using (var memstream = new MemoryStream()) { WriteableBitmap bmp = new WriteableBitmap(100, 75); bmp = bmp.FromStream(thumbStream); WriteableBitmap tBmp = bmp.Resize(100, 75, WriteableBitmapExtensions.Interpolation.NearestNeighbor); tBmp.SaveJpeg(memstream, 100, 75, 0, 90); memstream.Seek(0, SeekOrigin.Begin); ml.SavePictureToCameraRoll("mapi_thumb_" + fileName + ".jpg", memstream); } } stream.Close(); thumbStream.Close(); stream.Dispose(); thumbStream.Dispose(); }
private static void GetMetadata_GPS(HttpPostedFileBase item, out float?lng, out float?lat) { MemoryStream mStream = new MemoryStream(); item.InputStream.Position = 0; item.InputStream.CopyTo(mStream); mStream.Position = 0; var data = ExifFile.Read(mStream); if (data.Properties.ContainsKey(ExifTag.GPSLongitude)) { GPSLatitudeLongitude gps_lng = data.Properties[ExifTag.GPSLongitude] as GPSLatitudeLongitude; lng = gps_lng.ToFloat(); } else { lng = null; } if (data.Properties.ContainsKey(ExifTag.GPSLatitude)) { GPSLatitudeLongitude gps_lat = data.Properties[ExifTag.GPSLatitude] as GPSLatitudeLongitude; lat = gps_lat.ToFloat(); } else { lat = null; } }
//Image img0 = Image.FromFile(@"C:\temp\Pic1.jpg"); public static GPSLatitudeLongitude GetLatitudeDummy() { ExifFile file = ExifFile.Read(@"C:\temp\Pic1.jpg"); GPSLatitudeLongitude location = file.Properties[ExifTag.GPSLatitude] as GPSLatitudeLongitude; location.Degrees.Set(22, 0); return(location); }
/// <summary> /// Reads the GPS coordinate. /// </summary> private void ReadGPSCoordinate() { if (this.PhotoBitmap != null) { ISpatialCoordinate coord = null; Bitmap photo = this.PhotoBitmap; // Extract exif metadata ExifFile file = ExifFile.Read(this.FilePath); foreach (ExifProperty exifProperty in file.Properties) { Trace.WriteLine(exifProperty.Name.ToString() + "=" + exifProperty.Value.ToString()); } if (file.Properties.ContainsKey(ExifTag.GPSImgDirection)) { this.SetImageDirection(file.Properties[ExifTag.GPSImgDirection].Value.ToString()); } if (file.Properties.ContainsKey(ExifTag.GPSLatitude) && file.Properties.ContainsKey(ExifTag.GPSLongitude)) { float lon; float lat; GPSLatitudeLongitude latitude = (GPSLatitudeLongitude)file.Properties[ExifTag.GPSLatitude]; GPSLatitudeLongitude longitude = (GPSLatitudeLongitude)file.Properties[ExifTag.GPSLongitude]; lon = longitude.ToFloat(); lat = latitude.ToFloat(); if (file.Properties[ExifTag.GPSLongitudeRef].Value.ToString().StartsWith("W", StringComparison.CurrentCultureIgnoreCase)) { lon = lon * -1; } if (file.Properties[ExifTag.GPSLatitudeRef].Value.ToString().StartsWith("S", StringComparison.CurrentCultureIgnoreCase)) { lat = lat * -1; } if (lat != 0 & lon != 0) { coord = new Umbriel.GIS.Geohash.Coordinate(lon, lat); this.Coordinate = coord; } } } else { throw new NullReferenceException(); } }
/// <summary> /// 返回文件类型 /// </summary> /// <param name="file"></param> /// <returns></returns> static FileType GetFileType(string file) { if (ExtContains(file, ".jpeg|.gif|.jpg|.png|.bmp|.pic|.tiff|.ico|.iff|.lbm|.mag|.mac|.mpt|.opt|")) { ExifFile data; try { data = ExifFile.Read(file); } catch (Exception e) { Console.WriteLine(", read exif error."); return(FileType.Other); } foreach (ExifProperty item in data.Properties.Values) { if (item.Tag == ExifTag.DateTimeOriginal || item.Tag == ExifTag.DateTimeDigitized) { DateTime dt = (DateTime)item.Value; // 没有拍摄时间 if (dt.Year <= 1900) { return(FileType.Other); } else { return(FileType.Image); } } } return(FileType.Other); } if (ExtContains(file, ".mov|.avi|.rmvb|.rm|.asf|.divx|.mpg|.mpeg|.mpe|.wmv|.mp4|.mkv|.vob")) { var mf = new MediaFile(file); // 没有拍摄时间 if (mf.encodedDate.Year <= 1900) { return(FileType.Other); } else { return(FileType.Video); } } else { return(FileType.Other); } }
public static void ProcessImage(String filePath, DateTime newDateTime) { ExifFile image = ExifFile.Read(filePath); //Set the EXIF date/time values in the image and save it. try { image.Properties[ExifTag.DateTimeDigitized].Value = newDateTime; } catch (KeyNotFoundException) //No DateTimeDigitized? Add one. { var dateTime = new ExifDateTime(ExifTag.DateTimeDigitized, newDateTime); image.Properties.Add(ExifTag.DateTimeDigitized, dateTime); } try { image.Properties[ExifTag.DateTime].Value = newDateTime; } catch (KeyNotFoundException) //No DateTime? Add one. { var dateTime = new ExifDateTime(ExifTag.DateTime, newDateTime); image.Properties.Add(ExifTag.DateTime, dateTime); } try { image.Properties[ExifTag.DateTimeOriginal].Value = newDateTime; } catch (KeyNotFoundException) //No DateTimeOriginal? Add one. { var dateTimeOriginal = new ExifDateTime(ExifTag.DateTimeOriginal, newDateTime); image.Properties.Add(ExifTag.DateTimeOriginal, dateTimeOriginal); } try { image.Properties[ExifTag.ThumbnailDateTime].Value = newDateTime; } catch (KeyNotFoundException) //No ThumbnailDateTime? Add one. { var thumbnailDate = new ExifDateTime(ExifTag.ThumbnailDateTime, newDateTime); image.Properties.Add(ExifTag.ThumbnailDateTime, thumbnailDate); } image.Save(filePath); //Update the images' file creation time. File.SetCreationTime(filePath, newDateTime); }
public static void ProcessImage(String filePath) { ExifFile image = ExifFile.Read(filePath); DateTime whenDigitised = DateTime.MinValue; try { whenDigitised = (DateTime)image.Properties[ExifTag.DateTimeDigitized].Value; } catch (KeyNotFoundException) //EXIF data doesn't contain a DateTimeDigitized flag { return; } //Correct the EXIF values in the image and save it. try { image.Properties[ExifTag.DateTime].Value = whenDigitised; } catch (KeyNotFoundException) //No DateTime? Add one. { var dateTime = new ExifDateTime(ExifTag.DateTime, whenDigitised); image.Properties.Add(ExifTag.DateTime, dateTime); } try { image.Properties[ExifTag.DateTimeOriginal].Value = whenDigitised; } catch (KeyNotFoundException) //No DateTimeOriginal? Add one. { var dateTimeOriginal = new ExifDateTime(ExifTag.DateTimeOriginal, whenDigitised); image.Properties.Add(ExifTag.DateTimeOriginal, dateTimeOriginal); } try { image.Properties[ExifTag.ThumbnailDateTime].Value = whenDigitised; } catch (KeyNotFoundException) //No ThumbnailDateTime? Add one. { var thumbnailDate = new ExifDateTime(ExifTag.ThumbnailDateTime, whenDigitised); image.Properties.Add(ExifTag.ThumbnailDateTime, thumbnailDate); } image.Save(filePath); //Update the images' file creation time. File.SetCreationTime(filePath, whenDigitised); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { //Acquire the filePaths String[] filePaths = (String[])e.Argument; //Sort the files by name. Assumption is that the names are alpha-ordered. Array.Sort <String>(filePaths); //Convert the array to a list to make it easier to manipulate the contents. List <String> filePathsList = new List <String>(filePaths); //Get the first and last images' DateTimeDigitized values const Int32 FIRST = 0; Int32 LAST = filePathsList.Count - 1; ExifFile firstImage = ExifFile.Read(filePathsList[FIRST]); ExifFile lastImage = ExifFile.Read(filePathsList[LAST]); DateTime firstFileDigitisation, lastFileDigitisation, newFileDigitisation; firstFileDigitisation = (DateTime)firstImage.Properties[ExifTag.DateTimeDigitized].Value; lastFileDigitisation = (DateTime)lastImage.Properties[ExifTag.DateTimeDigitized].Value; newFileDigitisation = new DateTime(firstFileDigitisation.Ticks); //Determine the timespan between each image for the list. Int32 millisecondsBetweenFirstLast = Convert.ToInt32((lastFileDigitisation - firstFileDigitisation).TotalMilliseconds); Int32 millisecondsBetweenEachFile = millisecondsBetweenFirstLast / (filePathsList.Count - 1); //Remove the last and first images from the list, as were not going to process them. //These two files need to have the start & end date/times set. filePathsList.RemoveAt(filePathsList.Count - 1); filePathsList.RemoveAt(0); int numberProcessed = 1, progressPercentage = 0; foreach (var path in filePathsList) { if (backgroundWorker.CancellationPending) { e.Cancel = true; break; } newFileDigitisation = newFileDigitisation.AddMilliseconds(millisecondsBetweenEachFile); PhotoProcessor.ProcessImage(path, newFileDigitisation); progressPercentage = (numberProcessed++ *100) / filePathsList.Count; backgroundWorker.ReportProgress(progressPercentage); } }
private async Task ExifTest() { using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { var folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("shared\\transfers"); var images = await folder.GetFilesAsync(); var first = images.FirstOrDefault(); if (first == null) { return; } using (IsolatedStorageFileStream stream = storage.OpenFile(@"shared\\transfers\" + first.Name, FileMode.Open)) { ExifFile exif = ExifFile.ReadStream(stream); } } }
private void SaveImageToIsoStore(Stream stream, MemoryStream thumbStream) { string fileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff") + "#" + m_sequenceGuid.ToString(); ExifFile exif = ExifFile.ReadStream(stream); string metadata = GetMetadata(fileName); byte[] data = Encoding.UTF8.GetBytes(metadata); uint length = (uint)data.Length; ushort type = 2; var imgDescProp = ExifPropertyFactory.Get(0x010e, type, length, data, BitConverterEx.ByteOrder.BigEndian, IFD.Zeroth); exif.Properties.Add(ExifTag.ImageDescription, imgDescProp); using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isStore.DirectoryExists("shared")) { isStore.CreateDirectory("shared"); } if (!isStore.DirectoryExists("shared\\transfers")) { isStore.CreateDirectory("shared\\transfers"); } using (IsolatedStorageFileStream targetStream = isStore.OpenFile(@"shared\\transfers\" + fileName + ".jpg", FileMode.Create, FileAccess.Write)) { exif.SaveStream(targetStream); } using (IsolatedStorageFileStream thumbtargetStream = isStore.OpenFile(@"shared\\transfers\thumb_" + fileName + ".jpg", FileMode.Create, FileAccess.Write)) { WriteableBitmap bmp = new WriteableBitmap(100, 75); bmp = bmp.FromStream(thumbStream); WriteableBitmap tBmp = bmp.Resize(100, 75, WriteableBitmapExtensions.Interpolation.NearestNeighbor); tBmp.SaveJpeg(thumbtargetStream, 100, 75, 0, 90); } stream.Close(); thumbStream.Close(); stream.Dispose(); thumbStream.Dispose(); } }
protected void btnRun_Click(object sender, EventArgs e) { // var path = @"d:\45-banner1-test.jpg"; var path = txtPath.Text.Trim().Replace("\"", ""); var tmp = Path.GetFileNameWithoutExtension(Path.GetTempFileName()); var ext = Path.GetExtension(path); var filename = string.Format("{0}-{1}{2}", Path.GetFileNameWithoutExtension(path), tmp, ext); var targetFile = Path.Combine(Path.GetDirectoryName(path), filename); // Extract exif metadata var file = ExifFile.Read(path); // Clear metadata file.Properties.Clear(); // Save exif data with the image file.Save(targetFile); }
protected override void OnFetchingResponse() { Debug.Log("[DownloadTexture] Did finish downloading"); Texture2D _finalTexture = null; // Callbacks isnt set if (OnCompletion == null) { return; } // Encountered error while downloading texture if (!string.IsNullOrEmpty(WWWObject.error)) { Debug.Log("[DownloadTexture] Error=" + WWWObject.error); OnCompletion(null, WWWObject.error); return; } // Fix orientation to normal if (AutoFixOrientation) { Stream _textureStream = new MemoryStream(WWWObject.bytes); ExifFile _exifFile = ExifFile.Read(_textureStream); if (_exifFile != null && _exifFile.Properties.ContainsKey(ExifTag.Orientation)) { Orientation _orientation = (Orientation)_exifFile.Properties[ExifTag.Orientation].Value; Debug.Log("[DownloadTexture] Orientation=" + _orientation); switch (_orientation) { case Orientation.Normal: // Original image is used _finalTexture = WWWObject.texture; break; case Orientation.MirroredVertically: // Invert horizontally _finalTexture = WWWObject.texture.MirrorTexture(true, false); break; case Orientation.Rotated180: // Invert horizontally as well as vertically _finalTexture = WWWObject.texture.MirrorTexture(true, true); break; case Orientation.MirroredHorizontally: // Invert vertically _finalTexture = WWWObject.texture.MirrorTexture(false, true); break; case Orientation.RotatedLeftAndMirroredVertically: // Invert horizontally and rotate by -90 _finalTexture = WWWObject.texture.MirrorTexture(true, false).Rotate(-90); break; case Orientation.RotatedRight: // Rotate by 90 _finalTexture = WWWObject.texture.Rotate(90); break; case Orientation.RotatedLeft: // Invert vertically and rotate by -90 _finalTexture = WWWObject.texture.MirrorTexture(false, true).Rotate(-90); break; case Orientation.RotatedRightAndMirroredVertically: // Rotate by -90 _finalTexture = WWWObject.texture.Rotate(-90); break; } } else { _finalTexture = WWWObject.texture; } } // Use original image else { _finalTexture = WWWObject.texture; } OnCompletion(_finalTexture, null); }
protected override void OnFetchingResponse() { Texture2D _finalTexture = null; if (!string.IsNullOrEmpty(WWWObject.error)) { Debug.Log("[DownloadTexture] Failed to download texture. Error = " + WWWObject.error + "."); if (OnCompletion != null) { OnCompletion(null, WWWObject.error); return; } } Texture2D _tempTexture = WWWObject.texture; // Fix orientation to normal #if !UNITY_WINRT if (AutoFixOrientation) { Stream _textureStream = new MemoryStream(WWWObject.bytes); ExifFile _exifFile = null; try { _exifFile = ExifFile.Read(_textureStream); } catch (System.Exception e) { Debug.LogError("[DownloadTexture] Failed loading Exif data : " + e); } // Scale texture first before rotating for performance. if (ScaleFactor != 1f) { _tempTexture = _tempTexture.Scale(ScaleFactor); } if (_exifFile != null && _exifFile.Properties.ContainsKey(ExifTag.Orientation)) { Orientation _orientation = (Orientation)_exifFile.Properties[ExifTag.Orientation].Value; Debug.Log("[DownloadTexture] Orientation=" + _orientation); switch (_orientation) { case Orientation.Normal: // Original image is used _finalTexture = _tempTexture; break; case Orientation.MirroredVertically: // Invert horizontally _finalTexture = _tempTexture.MirrorTexture(true, false); break; case Orientation.Rotated180: // Invert horizontally as well as vertically _finalTexture = _tempTexture.MirrorTexture(true, true); break; case Orientation.MirroredHorizontally: // Invert vertically _finalTexture = _tempTexture.MirrorTexture(false, true); break; case Orientation.RotatedLeftAndMirroredVertically: // Invert horizontally and rotate by -90 _finalTexture = _tempTexture.MirrorTexture(true, false).Rotate(-90); break; case Orientation.RotatedRight: // Rotate by 90 _finalTexture = _tempTexture.Rotate(90); break; case Orientation.RotatedLeft: // Invert vertically and rotate by -90 _finalTexture = _tempTexture.MirrorTexture(false, true).Rotate(-90); break; case Orientation.RotatedRightAndMirroredVertically: // Rotate by -90 _finalTexture = _tempTexture.Rotate(-90); break; default: //If unknown orientation, just copying original texture _finalTexture = _tempTexture; Debug.LogWarning("[DownloadTexture] Unknown orientation found : " + _orientation); break; } } else { _finalTexture = _tempTexture; } } // Use original image else #endif { if (ScaleFactor != 1f) { _tempTexture = _tempTexture.Scale(ScaleFactor); } _finalTexture = _tempTexture; } if (OnCompletion != null) { OnCompletion(_finalTexture, null); } }
private void rotateBtn_Click(object sender, RoutedEventArgs e) { previewImage.Source = null; if (m_selectedFile != null) { Dictionary <ExifTag, ExifProperty> exifProperties = new Dictionary <ExifTag, ExifProperty>(); using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { WriteableBitmap bmp = new WriteableBitmap(0, 0); string exifData = null; using (var fileStream = storage.OpenFile(m_selectedFile.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { ExifFile exif = ExifFile.ReadStream(fileStream); var data = exif.Properties[ExifTag.ImageDescription]; exifData = (string)data.Value; fileStream.Close(); } using (var fileStream = storage.OpenFile(m_selectedFile.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { bmp = bmp.FromStream(fileStream); bmp = bmp.Rotate(90); fileStream.Close(); } lock (readLock) { using (IsolatedStorageFileStream stream = storage.CreateFile(@"shared\\transfers\" + m_selectedFile.Name)) { bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 98); stream.Close(); } } ExifFile exifRotated; using (var fileStream = storage.OpenFile(m_selectedFile.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { exifRotated = ExifFile.ReadStream(fileStream); fileStream.Close(); byte[] data = Encoding.UTF8.GetBytes(exifData); uint length = (uint)data.Length; ushort type = 2; var imgDescProp = ExifPropertyFactory.Get(0x010e, type, length, data, BitConverterEx.ByteOrder.BigEndian, IFD.Zeroth); exifRotated.Properties.Add(ExifTag.ImageDescription, imgDescProp); } lock (readLock) { using (IsolatedStorageFileStream targetStream = storage.OpenFile(m_selectedFile.Path, FileMode.Create, FileAccess.Write, FileShare.None)) { exifRotated.SaveStream(targetStream); targetStream.Close(); } } previewImage.Source = bmp; } } if (m_selectedThumbFile != null) { using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { var bmp = new WriteableBitmap(0, 0); bool exist = storage.FileExists(m_selectedThumbFile.Path); if (exist) { using (var fileStream = storage.OpenFile(m_selectedThumbFile.Path, FileMode.Open, FileAccess.Read, FileShare.None)) { bmp = bmp.FromStream(fileStream); bmp = bmp.Rotate(90); fileStream.Close(); } lock (readLock) { using (IsolatedStorageFileStream stream = storage.CreateFile(@"shared\\transfers\" + m_selectedThumbFile.Name)) { bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 98); stream.Close(); } } viewModel.PhotoList[m_selectionIndex - 1].ImageSource = new BitmapImage(new Uri(m_selectedThumbFile.Path)) { CreateOptions = BitmapCreateOptions.IgnoreImageCache }; } } } }
static void Main(string[] args) { string folderName = @"D:\test2"; string fileName = ""; string fileNameFull = ""; string dstFolderName = ""; string patternIPhoneJPG = "^P\\d{8}_\\d{6}"; string patternGalaxyJPG = "^\\d{4}-\\d{2}-\\d{2}-\\d{2}-\\d{2}-\\d{2}"; string patternIPhoneMOV = ".mov$"; string patternGalaxyMP4 = ".mp4$"; int jpgCount = 0; int videoCount = 0; int errorCount = 0; ExifFile fileExif; DateTime dateTime; if (System.IO.Directory.Exists(folderName)) { files = System.IO.Directory.GetFiles(folderName); foreach (string s in files) { //Console.WriteLine(s); fileNameFull = s; fileName = System.IO.Path.GetFileName(s); fileExif = ExifFile.Read(fileNameFull); //fileName = System.IO.Path.Combine(folderName, s); if (System.Text.RegularExpressions.Regex.IsMatch(fileName, patternIPhoneMOV)) { dstFolderName = folderName + "\\" + fileName.Substring(1, 8); //Console.WriteLine(dstFolderName); if (System.IO.Directory.Exists(dstFolderName)) { System.IO.Directory.Delete(dstFolderName, true); } System.IO.Directory.CreateDirectory(dstFolderName); System.IO.File.Copy(fileNameFull, dstFolderName + "\\" + fileName); Console.WriteLine("IPhone MOV : " + fileName + " -> " + dstFolderName); videoCount++; } else if (System.Text.RegularExpressions.Regex.IsMatch(fileName, patternGalaxyMP4)) { dstFolderName = folderName + "\\" + fileName.Substring(0, 8); //Console.WriteLine(dstFolderName); if (System.IO.Directory.Exists(dstFolderName)) { System.IO.Directory.Delete(dstFolderName, true); } System.IO.Directory.CreateDirectory(dstFolderName); System.IO.File.Copy(fileNameFull, dstFolderName + "\\" + fileName); Console.WriteLine("Galaxy MP4 : " + fileName + " -> " + dstFolderName); videoCount++; } else if (System.Text.RegularExpressions.Regex.IsMatch(fileName, patternIPhoneJPG)) { //fileName = fileName.Substring(1, 8) +"-"+ fileName.Substring(10, 6); //dateTime = fileName.Substring(7, 2) + "/" + fileName.Substring(5, 2) + "/"+fileName.Substring(1, 4)+" "+ fileName.Substring(10, 2)+":" + fileName.Substring(12, 2) + ":" + fileName.Substring(14, 2)+ " AM"; Console.WriteLine(fileName); int year = Convert.ToInt32(fileName.Substring(1, 4)); int month = Convert.ToInt32(fileName.Substring(5, 2)); int day = Convert.ToInt32(fileName.Substring(7, 2)); int hour = Convert.ToInt32(fileName.Substring(10, 2)); int minute = Convert.ToInt32(fileName.Substring(12, 2)); int second = Convert.ToInt32(fileName.Substring(14, 2)); //Console.WriteLine(year); //Console.WriteLine(month); //Console.WriteLine(day); //Console.WriteLine(hour); //Console.WriteLine(minute); //Console.WriteLine(second); //Console.WriteLine(year.ToString+month.ToString+day+hour+minute+second); dateTime = new DateTime(year, month, day, hour, minute, second); //Console.WriteLine("IPhone JPG : " + dateTime); //fileExif.Properties[ExifTag.DateTimeDigitized].Value = dateTime; fileExif.Properties[ExifTag.DateTimeOriginal].Value = dateTime; if (System.IO.Directory.Exists(folderName + @"\temp") == false) { System.IO.Directory.CreateDirectory(folderName + @"\temp\"); } fileExif.Save(folderName + @"\temp\" + fileName); jpgCount++; } else if (System.Text.RegularExpressions.Regex.IsMatch(fileName, patternGalaxyJPG)) { //dateTime = fileName.Substring(0, 4) + fileName.Substring(5, 2) + fileName.Substring(8, 2) +"-"+ fileName.Substring(11, 2) + fileName.Substring(14, 2) + fileName.Substring(17, 2); Console.WriteLine(fileName); int year = Convert.ToInt32(fileName.Substring(0, 4)); int month = Convert.ToInt32(fileName.Substring(5, 2)); int day = Convert.ToInt32(fileName.Substring(8, 2)); int hour = Convert.ToInt32(fileName.Substring(11, 2)); int minute = Convert.ToInt32(fileName.Substring(14, 2)); int second = Convert.ToInt32(fileName.Substring(17, 2)); //Console.WriteLine(year); //Console.WriteLine(month); //Console.WriteLine(day); //Console.WriteLine(hour); //Console.WriteLine(minute); //Console.WriteLine(second); //Console.WriteLine(year.ToString+month.ToString+day+hour+minute+second); dateTime = new DateTime(year, month, day, hour, minute, second); //Console.WriteLine("Galaxy JPG : " + dateTime); fileExif.Properties[ExifTag.DateTimeDigitized].Value = dateTime; fileExif.Properties[ExifTag.DateTimeOriginal].Value = dateTime; if (System.IO.Directory.Exists(folderName + @"\temp") == false) { System.IO.Directory.CreateDirectory(folderName + @"\temp\"); } fileExif.Save(folderName + @"\temp\" + fileName); jpgCount++; } else { Console.WriteLine("Nothing matched!!! = " + fileName); errorCount++; } //ExifFile file = ExifFile.Read(fileName); //file.Properties[ExifTag.DateTimeOriginal].Value = new DateTime(2017, 01, 02, 03, 04, 05, 06); //file.Save(fileName); //Console.WriteLine(fileName); //fileCount++; } Console.WriteLine("jpgCount = " + jpgCount); Console.WriteLine("videoCount = " + videoCount); Console.WriteLine("totalCount = " + (jpgCount + videoCount + errorCount)); } }