Get website thumbnail snapshot with C++
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
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.
精彩评论