Qt 4.8,大QGraphicsScene截图

Qt 4.8, Screenshot of large QGraphicsScene

我有 QGraphicsScene,大小是 62450x4750。有时我需要制作整个场景的屏幕截图并将其保存到文件中。我这样试过:

QPixmap wholeScene(scene.sceneRect().size().toSize());
{
    QPainter wholeScenePainter(&wholeScene);
    scene.render(&wholeScenePainter);
}
// saving pixmap

QPixmap wholeScene(scene.sceneRect().size().toSize());
{
    QPainter wholeScenePainter(&wholeScene);
    int x = 0;
    int portion = 32768; // 
    while( x < scene.sceneRect().width()) {
        int width = scene.sceneRect().width() - x > portion ? portion : scene.sceneRect().width() - x;
        QRect rect(x, 0, width, scene.sceneRect().height());
        scene.render(&wholeScenePainter, rect, rect);

        x += width;
    }
}
// saving pixmap

QPixmap wholeScene(scene.sceneRect().size().toSize());
{
    QPainter wholeScenePainter(&wholeScene);
    int x = 0;
    int portion = 4096;
    while( x < scene.sceneRect().width()) {
        int width = scene.sceneRect().width() - x > portion ? portion : scene.sceneRect().width() - x;
        QRect rect(x, 0, width, scene.sceneRect().height());

        QPixmap temp(rect.size());
        QPainter p(&temp);
        scene.render(&p, QRect(0, 0, rect.width(), rect.height()), rect);
        wholeScenePainter.drawPixmap(x,0, temp);
        //temp.save(QString("print%1.png").arg(QString::number(x)), "PNG");

        x += width;
    }
}
// saving pixmap

但是每次我得到按宽度切割 32768 像素的图像(像素图)时。

根据 Qt 5 中的 the documentation, QPainter does not support coordinates larger than +/- 32768. This does not appear to be fixed

也许您可以通过多次渲染场景来解决这个问题,例如通过翻译和剪辑。您可以在最大 32768x32768 像素的多个块中渲染场景,并将它们放在最终图像中的适当位置。