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();
}
}