Hello,
I want to take a screenshot of the MapGraphicsView and export it to png, jpg..
I tried this, but it returns just a grey picture:
//EsriRuntimeQt::MapGraphicsView* m_MapGraphicsView; auto pixmap = QPixmap::grabWidget(m_MapGraphicsView); QFile file(fileUrl.toLocalFile()); file.open(QIODevice::WriteOnly); pixmap.save(&file, "PNG");
Is there another way of taking a screenshot?
Thanks in advance!
Best regards,
Maximilian
Solved! Go to Solution.
Thank you for your answer Koushik, but it's the same result as before (see attachment).
This is what finally works for me (thanks to Norbert Thoden):
//QVBoxLayout* m_VBox QRect rect(m_VBox->itemAt(1)->geometry()); QMutex m(QMutex::NonRecursive); m.lock(); m.tryLock(100); auto pixmap = QGuiApplication::primaryScreen()->grabWindow(winId(),rect.x(), rect.y(), rect.width(), rect.height()); QFile file(fileUrl.toLocalFile()); file.open(QIODevice::WriteOnly); pixmap.save(&file, "PNG");
Best regards,
Maximilian Schönenberg
This doesn't directly help you right now, but I just wanted to let you know that with our Quartz release, there will be a function directly on the MapView that will export it to an image.
Ok, but Quartz isn't released yet. Is there another way of taking a screenshot of the MapView with 10.2.6?
You can try this. You might want to change the size of the rectangle. But this should work:
QRect rect(QPoint(0, 100), QSize(400, 400)) ; QPixmap image = QWidget::grab(rect); QString path = QDir::tempPath() + QString("/testImage.png"); bool success = image.save(path); qDebug() << success;
Possibly didn't work because there was no size specified maybe?
Thank you for your answer Koushik, but it's the same result as before (see attachment).
This is what finally works for me (thanks to Norbert Thoden):
//QVBoxLayout* m_VBox QRect rect(m_VBox->itemAt(1)->geometry()); QMutex m(QMutex::NonRecursive); m.lock(); m.tryLock(100); auto pixmap = QGuiApplication::primaryScreen()->grabWindow(winId(),rect.x(), rect.y(), rect.width(), rect.height()); QFile file(fileUrl.toLocalFile()); file.open(QIODevice::WriteOnly); pixmap.save(&file, "PNG");
Best regards,
Maximilian Schönenberg