我如何获得一个C#WebBrowser控件显示JPEG文件(生)? [英] How do I get a C# WebBrowser control to show jpeg files (raw)?

查看:334
本文介绍了我如何获得一个C#WebBrowser控件显示JPEG文件(生)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道的。Net 2.0 - 净3.5如何加载一个JPEG到System.Windows.Forms.WebControl作为一个字节数组并设定它会显示正确的MIME类型

Does anyone know in .Net 2.0 - .Net 3.5 how to load a jpeg into a System.Windows.Forms.WebControl as a byte-array and with the right mimetypes set so it will show?

是这样的:

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

在webBrowser1.DocumentType似乎只能读取,所以我不知道如何做到这一点。总的来说,我希望能够加载任何Filesource的与定义到浏览器中MIMETYPE表现出来。

The webBrowser1.DocumentType seems to be read only, so I do not know how to do this. In general I want to be able to load any kind of filesource with a mimetype defined into the browser to show it.

写作临时文件的解决方案是不好的。目前,我已经解决了它有一个小的本地网络服务器套接字监听器,可提供我要求用正确的mimetype的JPEG格式。

Solutions with writing temp files are not good ones. Currently I have solved it with having a little local webserver socket listener that delivers the jpeg I ask for with the right mimetype.

更新:既然有人删除了答案 - 我 - 自己的问题在那里我有其他人可以使用的信息,我将其添加为一个更新替代。 (那些谁删除的方式,请用更新的重要信息的问题)。

UPDATE: Since someone deleted a answer-my-own question where I had info that others could use, I will add it as an update instead. (to those who delete that way, please update the questions with the important info).

样的解决方案,完美的作品: HTTP:// WWW。 codeproject.com / KB / ASPNET / AspxProtocol.aspx

Sample solution in C# here that works perfectly: http://www.codeproject.com/KB/aspnet/AspxProtocol.aspx

推荐答案

您必须实现一个异步可插入协议,例如: IClassFactory的,IInternetProtocol ......然后你使用CoInternetGetSession注册您的协议。当IE调用你的实现,你可以从内存满足您的图像数据/提供MIME类型。

You have to implement an async pluggable protocol, e.g. IClassFactory, IInternetProtocol... Then you use CoInternetGetSession to register your protocol. When IE calls your implementation, you can serve your image data from memory/provide mime type.

这是一个有点乏味,但可行的。看看IInternetProtocol和可插拔的协议在 MSDN 的文档。

It's a bit tedious, but doable. Look at IInternetProtocol and pluggable protocols documentation on MSDN.

这篇关于我如何获得一个C#WebBrowser控件显示JPEG文件(生)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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