从特定浏览器中提取渲染的 HTML 图像
我正在开发一个应用程序,它将能够从特定浏览器中提取渲染的 HTML 图像。我希望用户能够选择特定的浏览器来渲染 HTML 文件,并捕获图像文件中的渲染输出。我还想立即捕获整个 HTML 渲染,而不仅仅是当时浏览器中可见的内容。
我从 IE8 开始,我不确定从哪里开始获得实际的渲染输出。我可以使用 Process.Start() 轻松地在该浏览器中打开文件,但我不知道如何返回渲染的输出。我看过一些沉没事件,但我不明白这是如何运作的,也不明白这是否是正确的方法。我只是想要一些方向,也许还有一些资源来引导我走上正确的道路。
I am working on an app that will be able to pull an image of rendered HTML from a specific browser. I would like the user to be able to select a specific browser to render an HTML file in, and capture the rendered output in an image file. I also want to capture the entire HTML render at once, not simply what is visible in the browser at the time.
I am starting with IE8, and I'm not sure where to begin to get the actual rendered output. I can easily open the file in that browser with Process.Start(), but I don't know how to return the rendered output. I have looked a little bit at sinking events, but I don't understand how that works or if that's the right way to go. I would just like some direction, and perhaps some resources to send me on the right path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你为什么要创造这个?现有的服务可以做完全相同的事情,例如 http://browsershots.org...
Why are you creating this? There are existing services that do the exact same thing, like http://browsershots.org...
如果您愿意依赖能够从用户屏幕上抓取图像(当然,并且在同一台 PC 上运行);您应该能够通过找到浏览器窗口边界矩形来做到这一点。然后使用 Graphics.CopyFromScreen 复制屏幕上显示的像素。
我在此处的答案中做了一个简单的示例,它向您展示了如何截取用户屏幕的屏幕截图。您应该很容易根据您的需要进行修改。
If you are willing to depend on being able to scrape the image from the user's screen (and running on the same PC, of course); you should be able to do this by finding the browser windows bounding rectangle. Then use Graphics.CopyFromScreen to copy the pixels as displayed on the screen.
I made a simple example in my answer here, which shows you how you can take a screenshot of the user's screen. Should be easy for you to modify to your needs.
已编辑。我以为您正在尝试在浏览器中捕获渲染的图像,例如 PNG、GIF 等。
如果您想将 HTML 输出捕获为图像,我会使用 WebBrowser 控件的 DrawToBitmap 方法...虽然它不是不是100%可靠。显然,对于开源浏览器(Webkit 等)来说,这变得容易得多。
Edited. I thought you were trying to capture a rendered image in the browser, like a PNG, GIF, etc.
If you want to capture the HTML output as an image, I'd use the WebBrowser control's DrawToBitmap method... though it isn't 100% reliable. And obviously for open-source browsers (Webkit, etc.) this gets a lot easier.