是否会猜测已经有一个基于 webkit/gecko 的命令行应用程序(甚至可以作为服务器加速渲染多个页面)已经在执行此操作?
问问题
1449 次
1 回答
7
这是一个示例 Qt4 命令行应用程序,它创建整个网页的屏幕抓图 - 易于适应缩略图生成......
#include <QtGui/QApplication>
#include <QtCore/QCoreApplication>
#include <QtGui>
#include <QtWebKit>
#include <QWebPage>
#include <QTextStream>
#include <QSize>
QWebView *view;
QString outfile;
void QWebView::loadFinished(bool ok)
{
QTextStream out(stdout);
if (!ok) {
out << "Page loading failed\n";
return;
}
view->page()->setViewportSize(view->page()->currentFrame()->contentsSize());
QImage *img = new QImage(view->page()->viewportSize(), QImage::Format_ARGB32);
QPainter *paint = new QPainter(img);
view->page()->currentFrame()->render(paint);
paint->end();
if(!img->save(outfile, "png"))
out << "Save failure\n";
QApplication::quit();
return;
}
int main(int argc, char *argv[])
{
QTextStream out(stdout);
if(argc < 3) {
out << "USAGE: " << argv[0] << " <url> <outfile>\n";
return -1;
}
outfile = argv[2];
QApplication app(argc, argv);
view = new QWebView();
view->load(QUrl(argv[1]));
return app.exec();
}
于 2009-08-24T07:16:27.347 回答