使用MediaElement

  这种方式有一个局限就是图片路径必须是绝对路径

 <MediaElement Source="file://C:\129.gif" />

  并且你还需要设置让他循环播放

<MediaElement Source="file://C:\129.gif" MediaEnded="MediaElement_MediaEnded"/>
  private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
{
((MediaElement)sender).Position=((MediaElement)sender).Position.Add(TimeSpan.FromMilliseconds());
}

通过winform中的PictureBox控件

  这种方式可以指定相对路径;首先,你需要在wpf程序中添加window的程序集引用:System.Drawing.dll、System.Windows.Forms.dll和WindowsFormsIntegration.dll

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAATgAAAEeCAIAAACR6J4WAAAUz0lEQVR4nO2dvY7kuHaA+0km200mXAX7APc1JtKbtGNlTvYBOp3gApU4G6OjyTzOCgMDt2DAqSczcAM6kEo6JA8lqloq8VDfBwJTpVZRP8NPpFg6p15cCVzaF5+mu45/Gl9fu+YlSXs5bO8Bdudl5m8/f/78+Ab+FrH8GSFnIOq0/No1k5veG4D6SIr6/fv3z58/51eUUhFRAT6OLur3799///33T58+5Vf0MVHDUS1DXwCJIur3799/++23T58+fUTU4MWSqJdWmkaPCuATiiotfV6P6ino44uacBNRoXI8UQNLnydqNOs79a8MfQGkqD9//vz8+fMnn49vYMPJJG98TI8KZ2Lu65mj8AbCk6i+jYgKZ6JEUb2ecxT10r7I+1hEhTNRjKjyBlQKeRfVnxe+uzl+KjUXBVAFxYgKAGkQFcAAiApgAEQFMACiAhgAUQEMgKgABkBUAAPULuq1a576MMTwBMYWz0kFj2LBqSlU1DXh5nFrvrTj4ueKeu2aDEdFrJB8VDJchqgwcbCoHwqO6y1swlDWoVM7opELtxLOXtpAz6a79kvvC8fnlhEVJsyL2naBEdeuabrumEa+JKoUUqDHzSMqTJQlavAiS9SL36L7N+Miz5dpeNl01/vfxDjZC2D3YnOUePZozTj6PQ4wSKinCnxpX5qua8MtK3sTHIh4S0x9LZQlqrp8UVTRzsWSUNRLGw6H+ybvuecJ3/9J6RoTay72qDN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nxfCsr3NuGvJ6Cc3E+81ElRcCoegluBf25rT8arwhcnQdiT7Od0UgKFTUfPpJJK/jku8fzGYSDX1lmpdmuv8dB8BawpdEjxrcud7rij6u5oiBk2Je1Cgbiv/+8WwmymTSvcL7+yiLcLC6P3pVpo2atlXSIc7OL8E5sS8qwAlAVAADICqAAXYR9Z9//kmhPKfs0YALBFEptsseDbhAEJViu+zRgAtkX1H3qBzAna+NISqY5GxtDFHBJGdrY7WLSiqWJ7PqhH+AgtrYUyhU1JyH8otPxRL9OttmNSe3dPyThoi6DweL+qEwt9JTsTw1iHRp33fdmQPCZRF1A54kaumpWBB1RxB1Ax4WNXixFI9aeCoWtfmqQTn9mpd22IFL+9J0l6G64VeR/b2bTfsSH6nYqIjjS58KGUgU7Fu8bb9y76DVg039R6wDUTfgST1q6alYvHvUURgt50O/pt++Zd6I5NVnIriIREcqP6MmeUmF5gb7puWRkZX7J1w7WHX3VoOoG/A0UctOxRL5lKo2XDNIMxq/nk/7okbe+qMPH/+UBXXMX4HSoiYPNhEYvBJE3YDnzPo658pOxZIjqrrmoqjxtlaKGtuRKaqeRyZT1PjkImouhYqaT8GpWOK+KFXtSlEX0r4siaoneZkb+k77puaRyRz6xpcURM3GvKgFp2JZO5kk11noUYNt+d+j6kc6rKNPCDnnLYwnk5yyksgjM1WeOZmEqCuxLyrsQfEPaZ2tjSEq9Fy7Rpv/LpWztTFEhTtiPFy4pe58bQxRwSRna2NkeKDYLns04AJBVIrtskcDLhBEpdguezTgAiGvL4ABdhH1f//7P//r3/4lVfbYIkDd7CLqP/79X//nP/7+fxq6qM9KCwBglP8H/FWc6oAkSF0AAAAASUVORK5CYII=" alt="" />

  引用类型后,你就可以在XAML代码中使用winform中的PictureBox了

  xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:winForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
  <wfi:WindowsFormsHost>
<winForms:PictureBox x:Name="PictureOfGif"></winForms:PictureBox>
</wfi:WindowsFormsHost>

  在程序load事件中绑定图片

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.PictureOfGif.Image = System.Drawing.Image.FromFile("images/129.gif");
}

WpfAnimatedGif

  可以通过控制台或者Nuget安装

Install-Package WpfAnimatedGif

xmlns:gif="http://wpfanimatedgif.codeplex.com"
<Image gif:ImageBehavior.AnimatedSource="Images/animated.gif" />

  GitHub地址:https://github.com/XamlAnimatedGif/WpfAnimatedGif

相关文档:

https://nnish.com/tag/animated-gif-in-wpf/

https://social.msdn.microsoft.com/Forums/vstudio/en-US/93d50a97-0d8d-4b18-992e-cd3200693337/how-to-use-an-animated-gif?forum=wpf

WPF显示GIF图的几种方式的更多相关文章

  1. 使用Photoshop切图的三种方式

    PhotoShop切图的三种方式 1. 原始切图 (1)选择工具栏中的切片工具 (2)找到要切片的元素,在右侧的图层框中,使元素背景隐藏,然后用切片工具选择需要切片的元素     (3)导出为web常 ...

  2. HTML中设置背景图的两种方式

    HTML中设置背景图的两种方式 1.background    background:url(images/search.png) no-repeat top; 2.background-image ...

  3. MATLAB 显示输出数据的三种方式

    MATLAB 显示输出数据的三种方式 ,转载 https://blog.csdn.net/qq_35318838/article/details/78780412 1.改变数据格式 当数据重复再命令行 ...

  4. Windows10-UWP中设备序列显示不同XAML的三种方式[3]

    阅读目录: 概述 DeviceFamily-Type文件夹 DeviceFamily-Type扩展 InitializeComponent重载 结论 概述 Windows10-UWP(Universa ...

  5. JavaScript+HTML+CSS 无缝滚动轮播图的两种方式

    第一种方式 在轮播图最后添加第一张,一张重复的图片. 点击前一张,到了第一张,将父级oList移动到最后一张(也就是添加的重复的第一张),在进行后续动画. 点击下一张,到了最后一张(也就是添加的重复的 ...

  6. 加载gif动态图的三种方式

    准备:本地图片资源,GifView

  7. ImageLoader框架的使用、调用系统相册显示图片并裁剪显示、保存图片的两种方式

    ImageLoader虽然说是一个相对于比较老的一个框架了 ,但是总的来说,还是比较好用的,今天我就总结了一下它的用法.还有调用系统相册并裁剪,以及,通过sharedpreference和文件存储来保 ...

  8. WPFの操作文件浏览框几种方式

    方式1: 使用win32控件OpenFileDialog Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog ...

  9. WPF内嵌网页的两种方式

    在wpf程序中,有时会内嵌网页.内嵌网页有两种方法,一种是使用wpf自带WebBrowser控件来调用IE内核,另一种是使用CefSharp包来调用chrom内核. 一.第一种使用自带WebBrows ...

随机推荐

  1. Reactive Extensions(Rx) 学习

    Bruce Eckel(著有多部编程书籍)和Jonas Boner(Akka的缔造者和Typesafe的CTO)发表了“反应性宣言”,在其中尝试着定义什么是反应性应用. 这样的应用应该能够: 对事件做 ...

  2. 8天掌握EF的Code First开发系列之动手写第一个Code First应用

    返回<8天掌握EF的Code First开发>总目录 本篇目录 创建控制台项目 根据.Net中的类来创建数据库 简单的CRUD操作 数据库模式更改介绍 本章小结 自我测试 上一篇<8 ...

  3. 谈谈D2

    很多参与了 D2 的人还不知道 D2 是个什么东西,印象中就是很多很多前端工程师汇聚在一起,交流技术.D2 是 D2前端技术论坛的简称,英文名 Designer & Developer Fro ...

  4. [nRF51822] 15、穿戴式设备上电量检测装置的设计及细节技术点(偏专业硬件文章)

    穿戴式 设备如智能手环.智能手表一般采用几百毫安时的锂离子电池来供电.因此,与之配套的充电电路.稳压电路和电池电量检测电路便必不可少!本文主要谈谈该类消费类电子内部电池电量检测的一般方法及其优缺点. ...

  5. 图解C#的值类型,引用类型,栈,堆,ref,out

    C# 的类型系统可分为两种类型,一是值类型,一是引用类型,这个每个C#程序员都了解.还有托管堆,栈,ref,out等等概念也是每个C#程序员都会接触到的概念,也是C#程序员面试经常考到的知识,随便搜搜 ...

  6. 解决微信公众号OAuth出现40029(invalid code,不合法的oauth_code)的错误

    关于OAuth 官方教程:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842&token=&la ...

  7. Mac下安装与配置Go语言开发环境

    1.官网下载安装包(需FQ) https://storage.googleapis.com/golang/go1.7.darwin-amd64.pkg 2.配置Go环境变量GOPATH和GOBIN ( ...

  8. VS web项目 基于IIS调试和模拟域名调试

    1.安装IIS 2.注册.net framework 到IIS 打开程序-运行-cmd:输入一下命令重新注册IISC:\WINDOWS\Microsoft.NET\Framework\v4.0.303 ...

  9. JS函数 -- 功能,语法,返回值,匿名函数,自调用匿名函数,全局变量与局部变量,arguments的使用

    “JavaScript设计得最出色的就是它的函数的实现.” -- <JavaScript语言精粹> 函数包含一组语句,它们是JS的基础模块单元,用于指定对象的行为.一般来说,所谓编程,就是 ...

  10. Android之genymotion模拟器安装于配置

    今天是双休日,可怜没人陪,只好一个人玩电脑了,之前别人一直给我推荐genymotion模拟器,说各种方便,秒杀Android自带模拟器,所以就趁这个周末搞了一下,总体感觉还挺不错的,确实比Androi ...