动画 Gif 不显示在 webBrowser 控件中

发布于 2024-08-28 10:38:13 字数 719 浏览 7 评论 0原文

我正在尝试将 gif 动画放到我的智能设备上。

我正在尝试使用网络浏览器控件来做到这一点。然后在表单加载上我使用以下代码:

String imgPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\PW.gif";

StringBuilder sb = new StringBuilder();
sb.Append("<html><body>");
sb.Append("<img src = \"" + imgPath + "\">");
sb.Append("</body></html>");

webBrowser1.DocumentText = sb.ToString();

但我得到一个红十字而不是图像。我查看了字符串生成器的值:

<html><body><img src = "\Program Files\FrontendTest\PW.gif"></body></html>

当我将其保存为 html 文件并在设备上运行它时,它工作得很好。

关于为什么它在网络浏览器控件中不起作用的任何想法?

谢谢 约翰

I am trying to put an animated gif on my smart device.

I am trying to do this using a webbrowser control. then on the form load i use the following code :

String imgPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\PW.gif";

StringBuilder sb = new StringBuilder();
sb.Append("<html><body>");
sb.Append("<img src = \"" + imgPath + "\">");
sb.Append("</body></html>");

webBrowser1.DocumentText = sb.ToString();

but i get a red cross instead of the image. I have taken a look at the value of the string builder it is :

<html><body><img src = "\Program Files\FrontendTest\PW.gif"></body></html>

When i save this as a html file and run it on the device it works perfect.

any ideas as to why it wouldnt work in the webbrowser control ??

Thanks
John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

邮友 2024-09-04 10:38:13

因为这是一种你知道的痛苦。不幸的是我今天遇到了同样的问题。试试这个(我不知道为什么会这样):

String imgPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\PW.gif"; 

StringBuilder sb = new StringBuilder();
sb.Append("<html><body>");
sb.Append("<img src = \"file:" + imgPath + "\">");
sb.Append("</body></html>");

webBrowser1.DocumentText = sb.ToString();

Because it's a pain in the you-know-what. Unfortunately I ran into the same problem today. Try this instead (I have no idea why this is the case):

String imgPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\PW.gif"; 

StringBuilder sb = new StringBuilder();
sb.Append("<html><body>");
sb.Append("<img src = \"file:" + imgPath + "\">");
sb.Append("</body></html>");

webBrowser1.DocumentText = sb.ToString();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文