Пример #1
0
        /// <summary>
        /// Loads a GIF file from the given path, and displays the resulting frames.
        /// </summary>
        /// <param name="path">The path to load the GIF file from.</param>
        private void LoadGif(string path)
        {
            FramesDisplayPanel.SuspendLayout();

            // Remove current panels.
            foreach (GifControl gc in FramesDisplayPanel.Controls)
            {
                gc.Dispose();
            }
            FramesDisplayPanel.Controls.Clear();

            GifImage <BitmapFrame> gifImage = null;

            try
            {
                using (var gifStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                    gifImage = new GifImage <BitmapFrame>(gifStream, BitmapFrame.FromBuffer, BitmapFrame.AllowableBitDepths);
            }
            catch (Exception)
            {
                // Couldn't load GIF, don't display.
                ImageInfo.Text = "Unable to load gif.";
                FramesDisplayPanel.ResumeLayout();
                return;
            }

            ImageInfo.Text =
                "Duration: {0:0.00s} Iterations: {1}  Size: {2}".FormatWith(
                    TimeSpan.FromMilliseconds(gifImage.Duration).TotalSeconds, gifImage.Iterations, gifImage.Size);

            var frames = gifImage.Frames;

            for (var i = 0; i < frames.Length; i++)
            {
                var info = "{0}: {1}ms".FormatWith(i + 1, frames[i].Duration);
                var gc   = new GifControl(frames[i], info);
                FramesDisplayPanel.Controls.Add(gc);
            }

            FramesDisplayPanel.ResumeLayout();
        }
Пример #2
0
        /// <summary>
        /// Loads a GIF file from the given path, and displays the resulting frames.
        /// </summary>
        /// <param name="path">The path to load the GIF file from.</param>
        private void LoadGif(string path)
        {
            FramesDisplayPanel.SuspendLayout();

            // Remove current panels.
            foreach (GifControl gc in FramesDisplayPanel.Controls)
            {
                gc.Dispose();
            }
            FramesDisplayPanel.Controls.Clear();

            GifImage <BitmapFrame> gifImage = null;

            try
            {
                using (FileStream gifStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                    gifImage = new GifImage <BitmapFrame>(gifStream, BitmapFrame.FromBuffer, BitmapFrame.AllowableBitDepths);
            }
            catch (Exception)
            {
                // Couldn't load GIF, don't display.
                ImageInfo.Text = "Unable to load gif.";
                FramesDisplayPanel.ResumeLayout();
                return;
            }

            ImageInfo.Text = string.Format(CultureInfo.CurrentCulture,
                                           "Iterations: {0}  Size: {1}", gifImage.Iterations, gifImage.Size);

            ImmutableArray <GifFrame <BitmapFrame> > frames = gifImage.Frames;

            for (int i = 0; i < frames.Length; i++)
            {
                string info = string.Format(CultureInfo.CurrentCulture,
                                            "{0}: {1}ms", i + 1, frames[i].Duration);
                GifControl gc = new GifControl(frames[i], info);
                FramesDisplayPanel.Controls.Add(gc);
            }

            FramesDisplayPanel.ResumeLayout();
        }