Javascript – Displaying an Image in a WebBrowser Control without accessing external Files

cjavascriptnetwebbrowser-control

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.

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.

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+?

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.

Edit: 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?)

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.

Best Answer

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...

Related Topic