为什么GifBitmapDecoder播放不完整的gif [英] Why GifBitmapDecoder play incomplete gif
问题描述
我想使用GifBitmapDecoder和Int32Animation播放gif图像,但是我发现某些gif播放时不完整.
I want to play a gif image using GifBitmapDecoder and Int32Animation, but I found some gif is incomplete when they were played.
这是我的gif:
这是我的测试代码:
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"/>
结果:
所以你能告诉我怎么了,因为我已经搜索了两天却什么也没找到...
So could you tell me what's wrong, since I have search for it two days and find nothing...
推荐答案
单个GIF帧可能只是图像在任意X,Y坐标处的一部分.
Individual GIF frames might be just portions of an image at any arbitrary X,Y-coordinate.
要在图像中正确放置框架,您将需要框架的X,Y坐标. 阅读有关如何获取此信息的文章:正在读取GifBitmapDecoder的Metadata属性...为什么它为null?
For properly placing a frame in the image, you will need the X,Y-coordinate of the frame. Read this post about how to get this information: Reading Metadata property of GifBitmapDecoder...why is it null?
然后要获得完整的图像,必须将框架与之前的框架合并,直到获得完整的图像.但是,假设您真正的"GIF播放器"只是将动画帧一个接一个地绘制(而不是将它们并排放置在StackPanel中),这将自动发生……
Then to get a complete image you must merge the frame with the previous frame(s), until a complete image is being obtained. However, assuming that your real "GIF player" just draws the animation frames one on top of another (instead of putting them side-by-side in a StackPanel), this would happen automagically...
这篇关于为什么GifBitmapDecoder播放不完整的gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!