将网页另存为图像 [英] Saving a web page as image

查看:126
本文介绍了将网页另存为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个爱好项目,我正在探索使用c / c ++ / javascript / java将网页(HTML)保存为图片的方法大多是以编程方式。到目前为止,我已经遇到了以下方式:

As a hobby project I am exploring the ways to save a web page (HTML) as image, mostly programatically using c/c++/javascript/java. Till now I have come across the following ways:


  1. 获取 IHTMLElement 使用它来查询 IHTMLElementRender ,然后使用它的 DrawToDC 方法( Ref: / strong> http://www.codeproject.com/KB/IP/htmlimagecapture.aspx )。但是问题是,它并不适用于所有的页面(大部分是嵌入了iframe的页面)。

  1. Get the IHTMLElement of page body and use it to query for IHTMLElementRender and then use its DrawToDC method (Ref: http://www.codeproject.com/KB/IP/htmlimagecapture.aspx ). But the problem is that it did not work for all the pages (mostly pages having embedded iframes).

我可以想到的另一种方法是使用一些web浏览器组件,当页面完全加载时,使用 BitBlt Ref: http://msdn.microsoft.com/en-us/library/dd183370%28VS.85%29.aspx )。但是问题是我要求的页面可能比我的屏幕尺寸长,并且不适合Web浏览器组件。

Another way which i can think of is to use some web browser component and when the pages is fully loaded then capture it using BitBlt (Ref: http://msdn.microsoft.com/en-us/library/dd183370%28VS.85%29.aspx ). But the problem is that the page I have requested may be longer than my screen size and it will not fit into the web browser component.

任何解决上述问题的方向/建议或替代方法都非常感谢。

Any direction/suggestion to resolve above issues or an alternative approach is greatly appreciated.

推荐答案

最终能够通过这两篇文章破解:

Well finally able to crack it by going through these two articles:


  1. http://www.codeproject.com/KB/GDI-plus/WebPageSnapshot.aspx [c#code-IE]

  2. http://www.codeproject.com/KB/graphics/IECapture。 aspx [c ++& GDI - IE]

  1. http://www.codeproject.com/KB/GDI-plus/WebPageSnapshot.aspx [c# code - IE]
  2. http://www.codeproject.com/KB/graphics/IECapture.aspx [c++ & GDI - IE]

无法共享代码,但上述两篇文章将为您提供最好的解决方案。

Can't share the code, but the above two articles will give you the best possible solution.

还请查看:

https://addons.mozilla.org/en-US/firefox/addon/3408/ [firefox + javascript]

https://addons.mozilla.org/en-US/firefox/addon/3408/ [firefox + javascript]

以上情况仍然可以。但不能保证总是工作。请查看以下链接:
如何使用IViewObject :: Draw?来渲染画布的可滚动区域?

Above things are still ok. BUT not guaranteed to work always. Check the below link: How do I render the scrollable regions of a canvas with IViewObject::Draw?

这篇关于将网页另存为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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