Getting a higher quality image from QWebPage



  • I'm creating an image capture utility to allow uses to download snapshots of the charts and graphs that our web application generates. I've used the "Framecapture":http://qt-project.org/doc/qt-5.0/qtwebkitexamples/webkitwidgets-framecapture.html example application as a starting point.

    It works well, but the image quality is too low for our needs. I need to be able to created higher resolution images.

    My understanding from reading the "QWebPage documentation":http://qt-project.org/doc/qt-5.1/qtwebkit/qwebpage.html#details is that I need to increase the pixel density ratio in the Viewports Attributes.

    Unfortunately, I cannot figure out how to do that. Seems like I might need to do something with the X11 server that QWebPage talks to to get the Viewports Attributes, but I'm not a real expert in any of this stuff, so am having a hard time figuring it out.

    Could somebody please give me some pointers?

    The code that I'm using is basically like this:

    @QWebPage m_page;
    m_page.mainFrame()->load(url);
    m_page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
    m_page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
    m_page.setViewportSize(1200,800);
    QImage image(m_page.mainFrame()->contentsSize(), QImage::Format_ARGB32_Premultiplied);
    image.fill(Qt::transparent);
    QPainter painter(&image);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setRenderHint(QPainter::TextAntialiasing, true);
    painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
    m_page.mainFrame()->documentElement().render(&painter);
    painter.end();
    image.save(fileName);@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.