1
当我开发我的WPF PC的应用程序,我用下面的代码,以显示我的GIF图像,因为我意识到有这样的没有简单的方法: -显示GIF图像
XAML:
<StackPanel Height="25" Name="stkProgressBar">
<wfi:WindowsFormsHost Background="Transparent" HorizontalAlignment="Center">
<winForms:PictureBox x:Name="pictureBoxLoading" Visible="False">
</winForms:PictureBox>
</wfi:WindowsFormsHost>
</StackPanel>
XAML.cs:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
this.pictureBoxLoading.Image = Properties.Resources.progressbar;
}
现在,当我用同样的方法在我的WPF浏览器中显示的图像(XBAP)应用程序,它不加载,因为此XAML代码的页面?任何想法为什么是这样,如果有任何其他方式在XBAP页面上显示GIF?
谢谢, Abhi。
==================
更新时间27/07/2010 11:AM
现在我尝试下面的代码: -
XAML:
<Image Name="Image1"></Image>
XAML.cs:
Stream imageStreamSource = new FileStream(@"C:\Inetpub\ExchangeRate\ExchangeRate\Image\progressbar.gif", FileMode.Open, FileAccess.Read, FileShare.Read);
GifBitmapDecoder decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
Int32Animation anim = new Int32Animation(0, decoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, decoder.Frames.Count/10, (int)((decoder.Frames.Count/10.0 - decoder.Frames.Count/10) * 1000))));
anim.RepeatBehavior = RepeatBehavior.Forever;
BitmapSource bitmapSource = decoder.Frames[0];
Image1.Source = bitmapSource;
Image1.Stretch = Stretch.None;
它显示图像没问题,但不是动画。我希望在这方面提供任何帮助。
Abhi。
一个信息。页面不会给出任何编译器错误,但在运行页面时会出错。 – 2010-07-27 09:02:47
http://zh.efreedom.com/Question/1-210922/How-do-I-get-an-animated-gif-to-work-in-WPF – Ragunathan 2010-07-27 12:45:54