如何使用 .NET CF 获取 WebBrowser 控件中所有页面的位图

发布于 2024-12-19 06:15:18 字数 472 浏览 3 评论 0原文

我有一个 WindowsMo​​bile 6.5(运行 .NET CF 2.0)应用程序,它嵌入了一个 WebBrowser 控件,可以呈现一些内容(远程生成)。我想将所有网页内容作为位图获取,以便能够将其发送到打印机(遗憾的是该打印机不支持打印 HTML)。

我知道这个问题已经在这里被问过: 获取网页的位图在.NET Compact Framework中使用WebBrowser Control

但是.NET Compact Framework没有可行的解决方案。 .NET Compact Framework 中不存在 WebBrowser.DrawToBitmap()。

如果您需要更多详细信息,请询问我。

I have an WindowsMobile 6.5 (running .NET CF 2.0) application that embed a WebBrowser control that render some content (generated remotely). I want to get all the web page content as a Bitmap, to be able to send it to a printer (sadly this printer do not supports printing HTML).

I know this question was already asked here:
Get bitmap of an web page using WebBrowser Control in .net compact framework

But there are no viable solution for the .NET Compact Framework. WebBrowser.DrawToBitmap() do not exists in .NET Compact Framework.

Please ask me if you need more details.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上得阳光 2024-12-26 06:15:18

您需要使用另一个库或API来进行HTML到位图的转换,这样您需要做的就是将文档文本或outerhtml发送到API,确保html页面中的所有链接是绝对的而不是相对的,或者具有基本标签在其中,让 API 进行转换,然后将位图发送到打印机。因此,如果您不能直接执行此操作,我会搜索 HTML 到位图 API 作为解决您问题的第二个选项,或作为后备选项。

.net 可能有这样的 API,并且我确信如果您不能以首选方式完成此操作,会有许多第三方 API 可供选择。

You need to use another library or API that does HTML to bitmap conversion, this way all you need to do is send the document text or outerhtml to the API, making sure all links in html page are absolute not relative, or has a base tag in it, let the API do the conversion, then send bitmap to printer. So if you can't do it directly I would search for a HTML to bitmap API as the second option to resolve your question, or as a fallback option.

.net might have such an API and I'm sure there would be many third party ones to choose from if you can't do it the preferred way.

情痴 2024-12-26 06:15:18
字符串 url = @"https://screenshotmachine.com/serve.php?img=example-org-FULL-1bdf72.png";

HttpWebRequest 请求 = (HttpWebRequest)WebRequest.Create(url);

使用 (HttpWebResponse 响应 = (HttpWebResponse)request.GetResponse())
使用(流流=response.GetResponseStream())
使用 (StreamReader reader = new StreamReader(stream))
{
    位图 bmp = new Bitmap(reader.ReadToEnd());
}
string url = @"https://screenshotmachine.com/serve.php?img=example-org-FULL-1bdf72.png";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
    Bitmap bmp = new Bitmap(reader.ReadToEnd());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文