public void BeginSlideShow() { // Reset Data CurrentPicture = null; ImagePaths.Clear(); // Validate SelectedPath var directories = SelectedPath.Split('%'); foreach (var directory in directories) { if (!Directory.Exists(directory)) { MessageBox.Show("A specified file path is not a real directory. Please ammend.", "Path Not Found", MessageBoxButton.OK, MessageBoxImage.Error); return; } } // Load Files var files = new List <string>(); foreach (var directory in directories) { LoadFiles(directory, ref files); } foreach (var file in files) { ImagePaths.Add(file); } // Shuffle ImagePaths.Shuffle(); // TODO: Check speedy loading // TODO: settings // Progress SlideshowProgress(null, null); }
private void SlideshowProgress(object sender, EventArgs e) { _dispatcherTimer.Stop(); _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 3500); if (CurrentPictureIndex >= ImagePaths.Count) { CurrentPictureIndex = 0; ImagePaths.Shuffle(); } WriteDebugEntry("Loading Image " + ImagePaths[CurrentPictureIndex]); BitmapImage newImage = null; try { newImage = new BitmapImage(new Uri(ImagePaths[CurrentPictureIndex])); CurrentPicture = newImage; } catch (NotSupportedException) { WriteDebugEntry("Unable to load image.. skipping"); CurrentPictureIndex++; _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1); _dispatcherTimer.Start(); } try { using (var reader = new ExifReader(ImagePaths[CurrentPictureIndex])) { object orignt = null; var orientation = reader.GetTagValue(ExifTags.Orientation, out orignt); if (orignt != null && ((ushort)orignt != 1)) { var transformBitmap = new TransformedBitmap(); transformBitmap.BeginInit(); transformBitmap.Source = newImage; switch ((ushort)orignt) { case 8: WriteDebugEntry(" Image required rotation :: RotateTransform(-90)"); transformBitmap.Transform = new RotateTransform(-90); break; case 6: WriteDebugEntry(" Image required rotation :: RotateTransform(90)"); transformBitmap.Transform = new RotateTransform(90); break; default: break; } transformBitmap.EndInit(); CurrentPicture = ((BitmapSource)transformBitmap).ToBitmapImage(); } } } catch (ExifLibException ex) { } switch (ImagePaths[CurrentPictureIndex].Split('.').Last().ToLowerInvariant()) { case "gif": WriteDebugEntry(" Image is gif :: setting up gif looping"); TimeSpan duration = TimeSpan.FromTicks(0); var gif = GifBitmapDecoder.Create(new Uri(ImagePaths[CurrentPictureIndex]), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); var delay = 0; foreach (var frame in gif.Frames) { frame.Freeze(); delay += (ushort)((BitmapMetadata)frame.Metadata).GetQuery("/grctlext/Delay"); } duration = TimeSpan.FromMilliseconds(delay * 10); if (duration < TimeSpan.FromSeconds(5)) { _dispatcherTimer.Interval = TimeSpan.FromTicks(duration.Ticks * 3); } else if (duration < TimeSpan.FromSeconds(10)) { _dispatcherTimer.Interval = TimeSpan.FromTicks(duration.Ticks * 2); } else { _dispatcherTimer.Interval = duration; } break; } CurrentPictureIndex++; _dispatcherTimer.Start(); }