How to get a C # WebBrowser control to display jpeg files (raw)?

Does anyone know in .Net 2.0 -.Net 3.5 how to load jpeg into System.Windows.Forms.WebControl as a byte array and with the correct mimetypes parameters so that it displays?

Sort of:

webBrowser1.DocumentStream = new MemoryStream(File.ReadAllBytes("mypic.jpg")); webBrowser1.DocumentType = "application/jpeg"; 

WebBrowser1.DocumentType seems to be read-only, so I don't know how to do this. In general, I want to be able to download any type of file using the mimetype defined in the browser to show it.

Solutions with temporary file files for writing are not good. I currently solved it with a small local web server socket listener that provides the jpeg I'm requesting with the correct mimetype type.

UPDATE: since someone deleted the question with my answer in which I had information that others could use, I will add it as an update. (for those who remove this path, please update the questions with important information).

An example solution in C # works fine here: http://www.codeproject.com/KB/aspnet/AspxProtocol.aspx

+3
source share
6 answers

You must implement an asynchronous plug-in protocol, for example. IClassFactory, IInternetProtocol ... Then you use CoInternetGetSession to register your protocol. When IE calls your implementation, you can serve your image data from memory / provide a mime type.

It is a bit tedious, but doable. See the documentation for IInternetProtocol and the pluggable protocols on MSDN .

+5
source

You cannot do this. You cannot create images in the Microsoft web browser.

The limitation comes from the IWebBrowser control itself, which .NET terminates.

0
source

If you need a general hack, try making your stream an HTML file that only shows your image. You lose the stream of bytes of the image and will have to write the image to disk.

0
source

IE only supports 32KB for embedded base64 encoded images, so it is not a good solution.

0
source

Try the res: protocol.

I have not tried it with .net dll, but this post says that it should work. Even if it requires a C ++ dll, it is much easier to use it for encoding.

I created a post that shows how to create a script resource here and how to use the res: protocol correctly.

0
source

Source: https://habr.com/ru/post/902072/


All Articles