Esempio n. 1
0
        private void EventSubs(bool Startup)
        {
            if (Startup)
            {
                mainWindow.MouseWheel           += MainWindow_MouseWheel;
                mainWindow.MouseRightButtonDown += delegate { ResetZoom(); };

                ZoomResetButton.Click += delegate { ResetZoom(); };

                // ImagePlayer
                ImagePlayer.MouseRightButtonDown += delegate { ResetZoom(); };
                ImagePlayer.MouseLeftButtonDown  += ImagePlayer_MouseLeftButtonDown;
                ImagePlayer.MouseLeftButtonUp    += ImagePlayer_MouseLeftButtonUp;
                ImagePlayer.MouseMove            += ImagePlayer_MouseMove;

                ImagePlayer.MaxHeight = SystemParameters.PrimaryScreenHeight * 85 / 100;
                ImagePlayer.MaxWidth  = SystemParameters.PrimaryScreenWidth * 85 / 100;

                // GIFPlayer
                GIFPlayer.MouseRightButtonDown += delegate { ResetZoom(); };
                GIFPlayer.MouseLeftButtonDown  += GIFPlayer_MouseLeftButtonDown;
                GIFPlayer.MouseLeftButtonUp    += GIFPlayer_MouseLeftButtonUp;
                GIFPlayer.MouseMove            += GIFPlayer_MouseMove;

                GIFPlayer.MaxHeight = SystemParameters.PrimaryScreenHeight * 85 / 100;
                GIFPlayer.MaxWidth  = SystemParameters.PrimaryScreenWidth * 85 / 100;
            }
            else
            {
                try
                {
                    mainWindow.MouseWheel -= MainWindow_MouseWheel;

                    // ImagePlayer
                    ImagePlayer.MouseLeftButtonDown -= ImagePlayer_MouseLeftButtonDown;
                    ImagePlayer.MouseLeftButtonUp   -= ImagePlayer_MouseLeftButtonUp;
                    ImagePlayer.MouseMove           -= ImagePlayer_MouseMove;

                    // GIFPlayer
                    GIFPlayer.MouseLeftButtonDown -= GIFPlayer_MouseLeftButtonDown;
                    GIFPlayer.MouseLeftButtonUp   -= GIFPlayer_MouseLeftButtonUp;
                    GIFPlayer.MouseMove           -= GIFPlayer_MouseMove;
                    GIFPlayer.MediaEnded          -= GIFPlayer_MediaEnded;
                    GIFPlayer.Close();
                    GIFPlayer.Source = null;

                    // filewatcher
                    watcher.Changed -= new FileSystemEventHandler(OnChanged);
                    watcher.Created -= new FileSystemEventHandler(OnChanged);
                    watcher.Deleted -= new FileSystemEventHandler(OnChanged);
                    watcher.Renamed -= new RenamedEventHandler(OnChanged);
                }
                catch (Exception)
                {
                    // ignore
                }
            }
        }
Esempio n. 2
0
        private void GIFPlayer_MediaEnded(object sender, RoutedEventArgs e)
        {
            if (!mediaPaused)
            {
                GIFPlayer.Position = new TimeSpan(0, 0, 1);

                GIFPlayer.Play();
            }
        }
Esempio n. 3
0
        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;
                }
            }
        }
Esempio n. 4
0
        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;
            }
        }