private void SetRename(ImageDetails imageDetails) { var datetime = new DateTime(imageDetails.DateTimeShot.Ticks + imageDetails.DeltaDatetime[0]); imageDetails.FileRename = String.Format("{0:000} - {1:d MMMM yyyy}.jpg", imageDetails.Index, datetime).ToLower(); }
private void FillList(ObservableCollection <ImageDetails> images, byte sourceIndex) { var start = DateTime.Now; var delteDatetime = new long[] { 0 }; var files = Directory.GetFiles(_currentDirectory); for (int i = 0; i < files.Count(); i++) { var file = files[i]; var extension = Path.GetExtension(file).ToLower(); if (_extensions.Contains(extension) == false) { continue; } if (extension == ".jpg") { var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read); var bitmapFrame = BitmapFrame.Create(fileStream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None); DateTime dt = DateTime.Now; if (((BitmapMetadata)bitmapFrame.Metadata).DateTaken != null) { dt = DateTime.Parse(((BitmapMetadata)bitmapFrame.Metadata).DateTaken); } else { if (i != 0) { int j = i - 1; BitmapFrame bitmapFrameTmp = BitmapFrame.Create(new Uri(files[j - 1])); for (; ((BitmapMetadata)bitmapFrameTmp.Metadata).DateTaken == null; j--) { bitmapFrameTmp = BitmapFrame.Create(new Uri(files[j - 1]), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None); } dt = DateTime.Parse(((BitmapMetadata)bitmapFrameTmp.Metadata).DateTaken); } else { throw new Exception("can`t set date"); } } fileStream.Close(); var camera = ((BitmapMetadata)bitmapFrame.Metadata).CameraManufacturer; if (camera != null) { camera = camera.Split(' ').First(); } var fi = new FileInfo(file); var id = new ImageDetails { Path = file, FileName = Path.GetFileName(file), Extension = Path.GetExtension(file), DateTimeShot = dt, Size = fi.Length, Width = bitmapFrame.PixelWidth, Height = bitmapFrame.PixelHeight, SourceIndex = sourceIndex, DeltaDatetime = delteDatetime, Camera = camera }; int i1 = i; Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (ThreadStart) delegate { var img = new BitmapImage(); img.BeginInit(); img.CacheOption = BitmapCacheOption.OnLoad; var k = Math.Min(id.Width / _imgWidth, id.Height / _imgHeight); img.DecodePixelWidth = id.Width / k; img.DecodePixelHeight = id.Height / k; img.UriSource = new Uri(files[i1], UriKind.Absolute); img.EndInit(); id.Width = img.PixelWidth; id.Height = img.PixelHeight; id.BitmapImage = img; images.Add(id); _images.Add(id); statusText.Text = String.Format("({0}/{1}) {2:0.00}sec", i1 + 1, files.Count(), (DateTime.Now - start).TotalSeconds * ((double)files.Count() / i1 - 1)); }); } } Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (ThreadStart)ImagesSort); }