winfrom PictureBox控件显示GIF图片异常解决方案
2013-06-04 11:02
405 查看
问题:最近开发winfrom项目显示图片用到PictureBox控件,同样一张图片,在win7跟XP电脑上运行得到的结果不一样,经过调试发现XP系统上用PictureBox显示GIF会出现bug(目前在win7使用PictureBox控件没有出现这个问题)
解决方案:
我的解决方案是重写这个控件,测试发现GIF帧数大于10以上的,都会出现问题。
下面的方法为我解决这个bug
解决方案:
我的解决方案是重写这个控件,测试发现GIF帧数大于10以上的,都会出现问题。
下面的方法为我解决这个bug
/// <summary> /// 显示图片方法 /// </summary> /// <param name="url"></param> private void ImgShow(string url) { if (url != null) { try { System.Net.WebClient web = new System.Net.WebClient(); byte[] buffer = web.DownloadData(url); web.Dispose(); System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer); Image img = Image.FromStream(ms, true, true); FrameDimension fd = new FrameDimension(img.FrameDimensionsList[0]); int count = img.GetFrameCount(fd);//获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧) if (count <= 10) { base.Image = img; } else { img.SelectActiveFrame(fd, 0); base.Image = img.GetThumbnailImage(img.Width, img.Height, () => { return false; }, IntPtr.Zero); } } catch (Exception) { base.Image = null; } } else { base.Image = null; } }
相关文章推荐
- Xcode9.2打包图片显示异常解决方案
- PictureBox控件中显示GIF动画(图片)
- Android三步显示gif动态图片
- android中自定义view显示gif格式图片
- MFC上显示GIF图片(使用 GIF Animation Control控件)
- vc 界面显示图片(JPG,jpeg .gif)
- IE和FF显示png图片透明的解决方案
- Qt Gif图片无法显示问题(WINDOWS)
- Android中显示gif图片
- 可以播放GIF和显示圆形图片的自定义ImageView
- 关于从相册取出图片后,图片不能按原来角度显示的问题解决方案
- 【iOS开发-29】解决方案:TabBar的图片不显示,只显示灰色的正方形
- GDI+中GIF图片的显示
- WebResource.axd异常 ,出现错误, TreeView节点图片不显示
- DataGridView单元格显示GIF图片
- 如何在ASP.NET页面中自动生成并显示透明的GIF图片
- Qt Gif图片无法显示问题(WINDOWS)
- PyQt4 QPixmap.load/loadFromData 使用py2exe 打包后无法显示JPEG,gif等图片的问题
- Windows Phone 实用开发技巧(8):在Windows Phone显示GIF图片 推荐
- qt生成的exe可执行程序打包到其他电脑上执行时jpg、gif图片不能正常显示,但png等其他格式可以显示