使用C ++获取网站缩略图快照(Get website thumbnail snapshot with C++)

有没有办法使用C ++ CGI捕获网页的图像? 我一直在寻找高低,虽然我已经在从Perl到C#的所有内容中找到了许多实现,却无法在C ++中找到任何实现。

想法是访问站点的用户能够指定URL。 然后该脚本将拍摄URL的网站,然后显示加载到我正在构建的C ++ CGI网站。

任何有关这方面的帮助将非常感谢!

谢谢!

Perl中的示例: Webthumb

Is there any way to capture an image of a web page using a C++ CGI? I've been searching high and low, and while I've found a number of implementations in everything from Perl to C#, haven't been able to find any implementations in C++.

The idea is for a user visiting a site to be able to specify a URL. The script would then take a picture of the URL's website, and then show load it to the C++ CGI website I am building.

Any help on this would be much appreciated!

Thanks!

Example in Perl: Webthumb

最满意答案

您需要呈现网页才能创建快照。 要在C ++中呈现页面,您需要包含一个浏览器引擎。 您可以使用Qt(c ++工具包)轻松完成此操作。 这取自Qt的文档,是您显示网页所需的全部内容。

QWebView *view = new QWebView(ui->centralWidget); view->load(QUrl("http://qt.nokia.com/")); view->show();

视图对象具有loadFinished信号。 您可以将一些代码连接到此信号。 呈现页面时,您可以按此处所述创建快照。 归结为:

QPixmap::grabWindow(mainwindow->winId())

获得截图后,您可以从cgi和完成后返回stdout上的字节。

You need to render the webpage in order to create a snapshot. To render the page in C++ you need to include a browser engine. You can do this easily using Qt (a toolkit for c++). This is taken from the documentation of Qt and is all you need to show a webpage.

QWebView *view = new QWebView(ui->centralWidget); view->load(QUrl("http://qt.nokia.com/")); view->show();

The view object has a loadFinished signal. You could connect some code to this signal. When the page is rendered you tak a snapshot as described here. It boils down to:

QPixmap::grabWindow(mainwindow->winId())

When you have got the screenshot you can return the bytes on stdout from your cgi and your done.

更多推荐