Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need to save/load img from/into graphicsview
Forum Updated to NodeBB v4.3 + New Features

Need to save/load img from/into graphicsview

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 3.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    droelf
    wrote on last edited by
    #1

    I need to save frames and also load the image again later.
    So my questions are:

    1. How to save images from GraphicsView/GraphicsScene

    2. 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? :/

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      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).

      D 1 Reply Last reply
      0
      • A alex_malyu

        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).

        D Offline
        D Offline
        droelf
        wrote on last edited by
        #3

        @alex_malyu

        Hmm, but its mentioned here.
        And GraphicsView is also available

        http://doc.qt.io/qt-5/paintsystem-images.html

        or here
        http://stackoverflow.com/questions/2430877/how-to-save-a-qpixmap-object-to-a-file

        So what do i have to do?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          droelf
          wrote on last edited by
          #4

          no ideas?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kenchan
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              LuGRU
              wrote on last edited by
              #6

              Hello,
              Reply to OP questions:

              1. 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
              2. 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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alex_malyu
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  droelf
                  wrote on last edited by droelf
                  #8

                  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 :)

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved