在Wpf中使用动态GIF图像的简单方法
2015-05-27 21:26
465 查看
Wpf本身的方法如果想加载GIF图像实在是过于复杂,我们可以通过使用winform控件,减少复杂性
方法一:利用winform控件 System.Windows.Forms. PictureBox pb = new System.Windows.Forms.PictureBox() { Width = 200, Height = 150, SizeMode = PictureBoxSizeMode .CenterImage }; pb.Image = System.Drawing. Image.FromFile(@"C:\Users\zez\Desktop\201203161640295.gif" ); System.Windows.Forms.Integration. WindowsFormsHost wfh = new System.Windows.Forms.Integration.WindowsFormsHost (); wfh.Child = pb; grid.Children.Add(wfh); 注 :System.Windows.Forms.Integration命名空间在V3.0中,有时需要单独添加引用 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\... 方法二:只能读取第一帧 BitmapImage img = new BitmapImage(); img.BeginInit(); img.UriSource = new Uri (@"C:\Users\zez\Desktop\201203161640295.gif"); img.DecodePixelWidth = 200; img.EndInit(); Border bor = new Border() { Width=300 ,Height=200 ,HorizontalAlignment= System.Windows.HorizontalAlignment .Left}; bor.Background = new ImageBrush (img); grid.Children.Add(bor); 方法三:使用解码器 Uri myUri = new Uri("tulipfarm.bmp", UriKind.RelativeOrAbsolute);//(第二个参数指定Uri地址) GifBitmapDecoder decoder2 = new GifBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); 通过decoder2.Frames可以获取gif所有帧,然后存入集合,循环播放,
相关文章推荐
- 使用动态SQL语句是最简单的处理方法。
- BCB中使用Image控件动态加载GIF、JPG文件出错的解决方法
- 读取JPEG和GIF图像的简单方法
- Winform和WPF也使用Sql Server CE4.0和EF的简单方法
- 使用jxl,Servlet,JSP 动态生成excel文件并提示下载的简单方法
- vc显示jpg,gif图像简单方法
- WPF中使用“全局变量”的简单方法
- vc显示jpg,gif图像简单方法
- word中使用动态图片(GIF)的方法
- 在wpf中使用Image时,时常会出现图像模糊的情况,有两种方法可以解决这一问题:(转)
- 在WPF中使用Emgu加载Image<,>图像的两种方法
- 在WPF中使用Emgu加载Image<,>图像的两种方法
- vc显示jpg,gif图像简单方法
- OJ常用动态数据输入方法 C++简单的栈编写及使用
- vc显示jpg,gif图像简单方法
- [KinectWPF程序]1深度图像,使用WriteableBitmap对象改进Kinect图像显示&复杂的Kinect初始化方法
- [KinectWPF程序]2彩色图像,使用WriteableBitmap对象改进Kinect图像显示&复杂的Kinect初始化方法
- java动态代理使用方法简单介绍
- Android之JNI动态注册native方法和JNI数据简单使用
- 使用numpy和PIL进行简单的图像处理方法