views:

990

answers:

2

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.

A: 

The img-tag supports inline data in its source attribute. So you can take your image data, base64-encode it, and store it inside the src attribute.

Look here for an example. og you can google for html embed image for more examples.

Rune Grimstad
The problem with the data: scheme is that it's not supported by older Internet Explorer Versions and that it's limited to 32k in newer ones :-(
Michael Stum
+2  A: 

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

Rune Grimstad
hmmm... That is actually not that much of a hack. The only possible issue is a Firewall complaining about my Application listening on a port, but it could connect on 127.0.0.1:unused_port and serve the images. Thinking about it, that is a neat solution.
Michael Stum