显示在WebBrowser控件图像,而无需访问外部文件 [英] Displaying an Image in a WebBrowser Control without accessing external Files

查看:107
本文介绍了显示在WebBrowser控件图像,而无需访问外部文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#在申请显示HTML。所有数据来自数据库,所以我生成与内联CSS一整页的内存并将其发送给浏览器。

I am using the WebBrowser Control in C# in an application to display HTML. All the data comes from a database, so I am generating a full page with Inline-CSS in Memory and sending it to the browser.

但现在我想支持图像,这似乎是一个问题,因为我不希望存储图像的硬盘上,即使是在一个临时目录。我知道了数据:URI方案,但是这似乎是太有限

But now I want to support images, which seems to be a problem because I do not want to store the images on Hard drive, not even in a Temp Directory. I am aware of the data: URI Scheme, but that seems to be too limited.

我在想:我可以以某种方式使用JavaScript动态生成图像,给出的字节流,基本上镜像数据:使用JavaScript计划?或者是有显示图像的一些其他的方式,即采用GDI +?

I wonder: Can I somehow use JavaScript to dynamically generate an image, given a stream of bytes, essentially mirroring the data: Scheme using JavaScript? Or is there some other way to display images, i.e. using GDI+?

我可以对如果需要的话,也就是我可以强制用户在指定的宽度和高度,如果需要的影像一些假设,但我真的不能强制执行的位置,它的HTML毕竟。我也可以强制所有以特定格式是图像,基本上任何可能有助于解决这一点。

I can make some assumptions about the images if required, i.e. I can force the user to specify width and height if required, but I cannot really enforce the position, it's HTML after all. I can also force all images being in a specific format, basically anything that could help solving this.

编辑:难道我也许虐待像 VML 显示位图数据?我不能用帆布或SVG,因为它似乎(包括不支持在IE浏览器,因此在MSHTML?)

Could I maybe abuse something like VML to display Bitmap data? I can't use Canvas or SVG as it seems (both unsupported in IE and therefore in MSHTML?)

编辑2: VML的工作,但处理器负载是疯了。因此,我将执行一项网络服务器来提供文件(如卡西尼),或尝试在我的其他问题的 Silverlight的做法

Edit 2: VML would work, but the processor load is insane. So I'll either implement a Webserver to serve files (like cassini) or try the Silverlight approach in my other question.

推荐答案

如果你愿意的复杂一层额外添加到您的应用程序,那么你可以嵌入可以用来服务于图像一个简单的Web服务器。 使用 System.Net.HttpListener 你可以设置你的应用程序以服务形象的要求。这应该工作,但似乎可怕的hackish ...

If you are willing to add an extra layer of complexity to your application then you can embed a simple web server that can be used to serve the images. Using the System.Net.HttpListener you can setup your application to serve the images as requested. This should work, but it seems terribly hackish...

这篇关于显示在WebBrowser控件图像,而无需访问外部文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆