private void GIFPlayer_MediaEnded(object sender, RoutedEventArgs e) { if (!mediaPaused) { GIFPlayer.Position = new TimeSpan(0, 0, 1); GIFPlayer.Play(); } }
public void OpenImage() { if (CurrentImage == LastImage) { return; } ResetZoom(); using (mediaStream = new FileStream(CurrentImage, FileMode.Open, FileAccess.Read)) { if (Path.GetExtension(CurrentImage) == ".gif") { using (Image gif = Image.FromStream(stream: mediaStream, useEmbeddedColorManagement: false, validateImageData: false)) { mediaPaused = false; ImagePlayer.Source = null; Uri imageUri = new Uri(CurrentImage); GIFPlayer.Source = imageUri; GIFPlayer.Width = gif.PhysicalDimension.Width; GIFPlayer.Height = gif.PhysicalDimension.Height; GIFPlayer.MediaEnded += GIFPlayer_MediaEnded; GIFPlayer.Play(); element = GIFPlayer; } } else { GIFPlayer.MediaEnded -= GIFPlayer_MediaEnded; GIFPlayer.Close(); GIFPlayer.Source = null; bitmap = new Bitmap(mediaStream); bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); ImagePlayer.Source = bitmapSource; bitmap.Dispose(); ImagePlayer.Width = ImagePlayer.Source.Width; ImagePlayer.Height = ImagePlayer.Source.Height; element = ImagePlayer; } } }
private void MainWindow_KeyDown(object sender, KeyEventArgs e) { base.OnKeyDown(e); switch (e.Key) { case Key.Left: SetCurrentImage(true); break; case Key.Right: SetCurrentImage(false); break; case Key.Up: ZoomIn(false); break; case Key.Down: ZoomOut(false); break; case Key.Space: if (GIFPlayer.Source != null) { if (!mediaPaused) { mediaPaused = true; GIFPlayer.Pause(); } else { mediaPaused = false; GIFPlayer.Play(); } } break; } }