0

I want to play a gif image using GifBitmapDecoder and Int32Animation, but I found some gif is incomplete when they were played.

Here is my gif:

enter image description here

And here is my test code:

GifBitmapDecoder _gifDecoder = new GifBitmapDecoder(
            new Uri("pack://application:,,,/Expression/f006.gif"), 
            BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

foreach (BitmapFrame bf in _gifDecoder.Frames)
{
     Image i = new Image { Source = bf };
     wp.Children.Add(i);
}

Xaml:

<WrapPanel Name="wp" ItemHeight="40" ItemWidth="40"/>

The result:

enter image description here

So could you tell me what's wrong, since I have search for it two days and find nothing...

4

1 回答 1

1

单个 GIF 帧可能只是任意 X、Y 坐标上图像的一部分。

为了在图像中正确放置框架,您将需要框架的 X、Y 坐标。阅读这篇关于如何获取此信息的帖子:Reading Metadata property of GifBitmapDecoder...why is null?

然后要获得完整的图像,您必须将帧与前一帧合并,直到获得完整的图像。但是,假设您真正的“GIF 播放器”只是将动画帧一个接一个地绘制(而不是将它们并排放置在 StackPanel 中),这将自动发生......

于 2013-11-15T03:41:51.367 回答