Yunan.WPF.ImageAnim.GifAnimation.CreateGifAnimation C# (CSharp) Method

CreateGifAnimation() public method

public CreateGifAnimation ( MemoryStream memoryStream ) : void
memoryStream System.IO.MemoryStream
return void
        public void CreateGifAnimation(MemoryStream memoryStream)
        {
            Reset();

            byte[] gifData = memoryStream.GetBuffer();  // Use GetBuffer so that there is no memory copy

            GifBitmapDecoder decoder = new GifBitmapDecoder(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

            _numberOfFrames = decoder.Frames.Count;

            try
            {
                ParseGif(gifData);
            }
            catch
            {
                throw new FileFormatException("Unable to parse Gif file format.");
            }

            for (int f = 0; f < decoder.Frames.Count; f++)
            {
                _frameList[f].Source = decoder.Frames[f];
                _frameList[f].Visibility = Visibility.Hidden;
                _canvas.Children.Add(_frameList[f]);
                Canvas.SetLeft(_frameList[f], _frameList[f].left);
                Canvas.SetTop(_frameList[f], _frameList[f].top);
                Canvas.SetZIndex(_frameList[f], f);
            }
            _canvas.Height = _logicalHeight;
            _canvas.Width = _logicalWidth;

            _frameList[0].Visibility = Visibility.Visible;

            for (int i = 0; i < _frameList.Count; i++)
            {
                Console.WriteLine(_frameList[i].disposalMethod.ToString() + " " + _frameList[i].width.ToString() + " " + _frameList[i].delayTime.ToString());
            }

            if (_frameList.Count > 1)
            {
                if (_numberOfLoops == -1)
                {
                    _numberOfLoops = 1;
                }

                frameTimer = new System.Windows.Threading.DispatcherTimer();
                frameTimer.Interval = new TimeSpan(0, 0, 0, 0, _frameList[0].delayTime * 10);
                frameTimer.Start();
            }
        }

Usage Example

Example #1
0
 private void CreateGifAnimation(MemoryStream memoryStream)
 {
     _gifAnimation = new GifAnimation();
     _gifAnimation.CreateGifAnimation(memoryStream);
     _gifAnimation.Stretch          = Stretch;
     _gifAnimation.StretchDirection = StretchDirection;
     this.AddChild(_gifAnimation);
 }
All Usage Examples Of Yunan.WPF.ImageAnim.GifAnimation::CreateGifAnimation