Need to save/load img from/into graphicsview
-
I need to save frames and also load the image again later.
So my questions are:-
How to save images from GraphicsView/GraphicsScene
-
Where are they saved and how can i load them into the View/Scene again?
What i found was this:
void MainWindow::save_image(){ QPixmap pixMap = this->ui->graphicsView->grab(); pixMap.save(QString::number(this->myLogic->my_updater->frame_counter)+".png"); }
Any infos? :/
-
-
Graphics scene does not operate with images.
It operates with QGraphicsItem subclasses.So to save and then restore state you need to write/read code of every item (position and properties).
-
Hmm, but its mentioned here.
And GraphicsView is also availablehttp://doc.qt.io/qt-5/paintsystem-images.html
or here
http://stackoverflow.com/questions/2430877/how-to-save-a-qpixmap-object-to-a-fileSo what do i have to do?
-
no ideas?
-
So do you mean you want to take a screen shot of the screen or save the content of a particular QGraphicsBitmapItem to a file?
-
Hello,
Reply to OP questions:- User QGraphicsView::render (of course set scene before - note - scene can be set to multiple views) - http://doc.qt.io/qt-5/qgraphicsview.html#render
- In location that image was saved.
To save multiple frames You will need to "progress" animation and at each progress step write image to file. To load images to scene just use convenience objects i.e. QPixmapItem - http://doc.qt.io/qt-5/qgraphicspixmapitem.html or write You own implementation.
To display animation from images (I do assume You will end up with image sequence) write custom class based on QPixmapItem or just QGraphicsItem.
-
you can take a screenshot of any widget , but you can't restore graphicsview from it, at least not in editable form.
If you want to be able to save state of the widget you need to do what I said above. -
The Code i posted was right, i just searched in the wrong folders.
So this is how it works to Save/Load:void MainWindow::save_image(){ QPixmap pixMap = this->ui->graphicsView->grab(); pixMap.save(QString::number(this->myLogic->my_updater->frame_counter)+".png"); } void MainWindow::load_image(int n){ QString number = QString::number(n); QString s = number +".png"; QPixmap p; p.load(s); QGraphicsPixmapItem* item = new QGraphicsPixmapItem(p); scene->clear(); scene->addItem(item); this->ui->graphicsView->show(); }
And thx for the help to all :)