Exemple #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
                }
            }
        }
Exemple #2
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;
                }
            }
        }