Hi Folks,
I use the following code to save a selection of a scene into a file (Qt 4.7.4):
if (mpScene->selectedItems().isEmpty()) return;
QList<QGraphicsItem*> items(mpScene->selectedItems());
sourceRect = sourceRect.united(item->sceneBoundingRect().toRect());
}
QImage img
(sourceRect.
size(),
QImage::Format_ARGB32_Premultiplied);
mpView->scene()->clearSelection();
mpView
->scene
()->render
(&p,
QRectF(), sourceRect
);
p.end();
img.save(path,"JPG",100);
if (mpScene->selectedItems().isEmpty()) return;
QList<QGraphicsItem*> items(mpScene->selectedItems());
QRect sourceRect;
boostForeach(QGraphicsItem* item, items) {
sourceRect = sourceRect.united(item->sceneBoundingRect().toRect());
}
QImage img(sourceRect.size(),QImage::Format_ARGB32_Premultiplied);
QPainter p(&img);
mpView->scene()->clearSelection();
mpView->scene()->render(&p, QRectF(), sourceRect);
p.end();
QString path = QFileDialog::getSaveFileName(0,tr("Choose Image-File Destination"));
img.save(path,"JPG",100);
To copy to clipboard, switch view to plain text mode
While the code works fine, the result is not satisfactory at all.
The following image is what I get:
test2.jpg
It seems like the renderer stops it's work in the middle or some cache is not written.
This does not happen with bigger scenes but selections rectangles are almost always corrupted
Has anybody any idea where this might come from ?
Bookmarks