Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Italian
  4. Visualizzare un'immagine e copiarne una porzione

Visualizzare un'immagine e copiarne una porzione

Scheduled Pinned Locked Moved Solved Italian
15 Posts 2 Posters 4.4k Views
  • 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.
  • V Offline
    V Offline
    VRonin
    wrote on 27 Feb 2017, 11:43 last edited by
    #6

    prova a sostituire QPixmap a = image.copy(rect); con ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect));

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    P 1 Reply Last reply 27 Feb 2017, 11:46
    0
    • V VRonin
      27 Feb 2017, 11:43

      prova a sostituire QPixmap a = image.copy(rect); con ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect));

      P Offline
      P Offline
      Polielia
      wrote on 27 Feb 2017, 11:46 last edited by
      #7

      @VRonin said in Visualizzare un'immagine e copiarne una porzione:

      ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect));

      se ho scritto giusto

      QPixmap a = ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect));
      

      ho il seguente errore

      ...\gui\button1_nyq.cpp:224: error: conversion from 'void' to non-scalar type 'QPixmap' requested
               QPixmap a = ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect));//copy the selected image in a
                                                                                ^
      
      1 Reply Last reply
      0
      • V Offline
        V Offline
        VRonin
        wrote on 27 Feb 2017, 12:01 last edited by VRonin
        #8

        togli QPixmap a =

         QPixmap image(rect.size());
                ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect)); //copio l'immagine selezionata in a
                ui->label_image_selected->setPixmap(a); //mostro l'immagine nel secondo QLabel
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        P 2 Replies Last reply 27 Feb 2017, 12:04
        0
        • V VRonin
          27 Feb 2017, 12:01

          togli QPixmap a =

           QPixmap image(rect.size());
                  ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect)); //copio l'immagine selezionata in a
                  ui->label_image_selected->setPixmap(a); //mostro l'immagine nel secondo QLabel
          
          P Offline
          P Offline
          Polielia
          wrote on 27 Feb 2017, 12:04 last edited by Polielia
          #9

          @VRonin

          ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect));
          ui->label_image_selected->setPixmap(a); //show the image selected
          

          cosi mi dice

          ...\gui\button1_nyq.cpp:224: error: no matching function for call to 'QLabel::render(int*, QPoint, QRegion)'
                   ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect));//copy the selected image in a
                                                                        ^                                      ^
          

          e per la seconda riga

          ...\gui\button1_nyq.cpp:227: error: no matching function for call to 'QLabel::setPixmap(int&)'
                   ui->label_image_selected->setPixmap(a); //show the image selected
                                                        
          
          1 Reply Last reply
          0
          • V VRonin
            27 Feb 2017, 12:01

            togli QPixmap a =

             QPixmap image(rect.size());
                    ui->ImageDisplay->render(&a,QPoint(0,0),QRegion(rect)); //copio l'immagine selezionata in a
                    ui->label_image_selected->setPixmap(a); //mostro l'immagine nel secondo QLabel
            
            P Offline
            P Offline
            Polielia
            wrote on 27 Feb 2017, 12:15 last edited by Polielia
            #10

            @VRonin ok scusa colpa mia, cambiando quella riga mi sono dimenticato che a era un intero usato da un'altra parte
            quindi:

            QPixmap image(rect.size());
                    ui->ImageDisplay->render(&k,QPoint(0,0),QRegion(rect)); //copio l'immagine selezionata in a
                    ui->label_image_selected->setPixmap(k); //mostro l'immagine nel secondo QLabel
            

            ora però mi da giustamente errore su k, dicendo che non è dichiarato

            edit:
            provando a dichiarare k come un QPixmap: il rettangolo è sempre disegnato in posizione diversa da quella del primo click, non viene visualizzato nulla nel secondo label

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VRonin
              wrote on 27 Feb 2017, 12:51 last edited by VRonin
              #11

              Che casino che abbiamo fatto. ok,

              QPixmap image(rect.size());
                      ui->ImageDisplay->render(&image,QPoint(0,0),QRegion(rect)); //copio l'immagine selezionata in image
                      ui->label_image_selected->setPixmap(image); //mostro l'immagine nel secondo QLabel
              

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              P 1 Reply Last reply 27 Feb 2017, 12:59
              0
              • V VRonin
                27 Feb 2017, 12:51

                Che casino che abbiamo fatto. ok,

                QPixmap image(rect.size());
                        ui->ImageDisplay->render(&image,QPoint(0,0),QRegion(rect)); //copio l'immagine selezionata in image
                        ui->label_image_selected->setPixmap(image); //mostro l'immagine nel secondo QLabel
                
                P Offline
                P Offline
                Polielia
                wrote on 27 Feb 2017, 12:59 last edited by Polielia
                #12

                @VRonin
                ok allora il codice che ho ora è

                void Button1_nyq::on_selectimage_nyq_Hom_clicked() 
                {
                
                        Imagename = QFileDialog::getOpenFileName(this,tr("Open Image for Nyquist Test"), "", tr("Images (*.jpg)"));  //apro l'immagine
                        //mostro l'immagine
                        QPixmap image(Imagename);
                        ui->ImageDisplay->setPixmap(image);  //ImageDisplay è il nome del QLabel
                    }
                int count_selection=0; //quando è diverso da 0 faccio sparire vuol dire che l'utente vuole disegnare un altro rettangolo, quindi nascondo il precedente
                
                void Button1_nyq::mousePressEvent(QMouseEvent *e)
                {
                        if(count_selection!=0)
                                rubberBand->hide();
                        point1 = e->pos();
                        rubberBand = new QRubberBand(QRubberBand::Rectangle,this );
                }
                
                void Button1_nyq::mouseMoveEvent(QMouseEvent *e)
                {
                        rubberBand->show();
                        rubberBand->setGeometry(QRect(point1,e->pos()));
                }
                
                void Button1_nyq::mouseReleaseEvent(QMouseEvent *e)
                {
                        count_selection++;
                        QRect rect; //selection rectangle
                        rect.setTopLeft(point1);
                        rect.setBottomRight(e->pos()));
                       QPixmap image(rect.size());
                        ui->ImageDisplay->render(&image,QPoint(0,0),QRegion(rect)); //copio l'immagine selezionata in image
                        ui->label_image_selected->setPixmap(image); //mostro l'immagine nel secondo QLabel
                
                

                cosi,usando pos, al posto di globalpos il rettangolo viene visualizzato correttamente e l'immagine copiata è più precisa rispetto a prima, nel senso che prima veniva traslata su 2 dimesioni, ora invece viene visualizzata un'immagine di poco traslata solo sull'asse x. Hai idee per questo?
                usando globalpos non sono riuscito a disegnare il rettangolo correttamente

                Questo è il risultato che ottengo ora:
                Real image
                http://imgur.com/9f6e0D3
                Selected image
                http://imgur.com/lysvM0q
                Result
                http://imgur.com/s0FydTc

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Polielia
                  wrote on 28 Feb 2017, 09:33 last edited by
                  #13

                  Ho risolto il problema, questa è la mia soluzione per chi dovvesse avere lo stesso inconveniente

                  void Button1_nyq::on_selectimage_nyq_Hom_clicked() 
                  {
                   
                          Imagename = QFileDialog::getOpenFileName(this,tr("Open Image for Nyquist Test"), "", tr("Images (*.jpg)"));  //apro l'immagine
                          //visualize the image in the first Label
                          QPixmap image(Imagename);
                          ui->ImageDisplay->setPixmap(image);  //ImageDisplay is the name of QLabel
                      }
                   
                  void Button1_nyq::mousePressEvent(QMouseEvent *e)
                  {
                   
                          point1 = e->pos();
                          rubberBand = new QRubberBand(QRubberBand::Rectangle,this );
                  }
                   
                  void Button1_nyq::mouseMoveEvent(QMouseEvent *e)
                  {
                          rubberBand->show();
                          rubberBand->setGeometry(QRect(point1,e->pos()));
                  }
                   
                  void Button1_nyq::mouseReleaseEvent(QMouseEvent *e)
                  {
                          rubberband->hide();
                          QRect rect; //selection rectangle
                          rect.setTopLeft(point1);
                          rect.setBottomRight(e->pos()));
                   
                         QPixmap image(rect.size());
                         image = grab(rubberband->geometry()); //copy the selected part
                          ui->label_image_selected->setPixmap(image); //show "image" in the second QLabel
                  
                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    VRonin
                    wrote on 28 Feb 2017, 09:53 last edited by VRonin
                    #14

                    La via giusta comunque sarebbe usare il framework QGraphicView o la moderna alternativa in Qt Quick. QLabel e' progettata per essere un display di scritte o immagini, non per iteragirvi

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    P 1 Reply Last reply 28 Feb 2017, 09:56
                    0
                    • V VRonin
                      28 Feb 2017, 09:53

                      La via giusta comunque sarebbe usare il framework QGraphicView o la moderna alternativa in Qt Quick. QLabel e' progettata per essere un display di scritte o immagini, non per iteragirvi

                      P Offline
                      P Offline
                      Polielia
                      wrote on 28 Feb 2017, 09:56 last edited by
                      #15

                      @VRonin
                      Non sono ancora così esperto, quindi grazie per avermi dato questi spunti ;)

                      1 Reply Last reply
                      0

                      15/15

                      28 Feb 2017, 09:56

                      • Login

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