跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  2. Qt Development
  3. General and Desktop
  4. Picture
Forum Updated to NodeBB v4.3 + New Features

Picture

已排程 已置頂 已鎖定 已移動 Solved General and Desktop
82 貼文 7 Posters 46.5k 瀏覽 3 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • VRoninV 離線
    VRoninV 離線
    VRonin
    寫於 最後由 編輯
    #54

    ok, now we are making progress. you got what the dominant colour is, now you have to paint the rectange

    "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

    1 條回覆 最後回覆
    2
    • P 離線
      P 離線
      Payx
      寫於 最後由 編輯
      #55

      @VRonin said in Picture:

      ok, now we are making progress. you got what the dominant colour is, now you have to paint the rectange

      sorry if don't listen to you very well but

      it say that my function isnt declared (dominantColor)

      1 條回覆 最後回覆
      0
      • VRoninV 離線
        VRoninV 離線
        VRonin
        寫於 最後由 編輯
        #56

        http://www.cplusplus.com/doc/tutorial/functions/#declarations

        "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

        1 條回覆 最後回覆
        0
        • P 離線
          P 離線
          Payx
          寫於 最後由 編輯
          #57

          Okay i fixed it

          MainWindow::MainWindow(QWidget *parent) :
          	QMainWindow(parent),
          	ui(new Ui::MainWindow)
          {
          		ui->setupUi(this);
          
          }
          QColor dominantColor(const QImage& image, const QPoint& topLeft, const QSize& rectSize);
          void fillSection(QImage& image, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);
          
          MainWindow::~MainWindow()
          {
          	delete ui;
          }
          

          So now with, fillSection, the problem i have is to declare something who correspond to QColor& colour

          i check the code again, and i think its colourList no ?

          VRoninV 1 條回覆 最後回覆
          0
          • P Payx

            Okay i fixed it

            MainWindow::MainWindow(QWidget *parent) :
            	QMainWindow(parent),
            	ui(new Ui::MainWindow)
            {
            		ui->setupUi(this);
            
            }
            QColor dominantColor(const QImage& image, const QPoint& topLeft, const QSize& rectSize);
            void fillSection(QImage& image, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);
            
            MainWindow::~MainWindow()
            {
            	delete ui;
            }
            

            So now with, fillSection, the problem i have is to declare something who correspond to QColor& colour

            i check the code again, and i think its colourList no ?

            VRoninV 離線
            VRoninV 離線
            VRonin
            寫於 最後由 編輯
            #58

            sorry if don't listen to you very well but

            No worries, I'm explicitly refraining from giving you the exact answer and rather trying to send you on the right path.

            i check the code again, and i think its colourList no ?

            Nope, colourList will die: http://www.cplusplus.com/doc/tutorial/namespaces/#scopes

            "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 條回覆 最後回覆
            0
            • VRoninV VRonin

              sorry if don't listen to you very well but

              No worries, I'm explicitly refraining from giving you the exact answer and rather trying to send you on the right path.

              i check the code again, and i think its colourList no ?

              Nope, colourList will die: http://www.cplusplus.com/doc/tutorial/namespaces/#scopes

              P 離線
              P 離線
              Payx
              寫於 最後由 編輯
              #59

              @VRonin said in Picture:

              Nope, colourList will die: http://www.cplusplus.com/doc/tutorial/namespaces/#scopes

              Ok i got it, we will put the returned color from QColor dominantColor, thats right ?

              1 條回覆 最後回覆
              2
              • VRoninV 離線
                VRoninV 離線
                VRonin
                寫於 最後由 編輯
                #60

                Getting warmer and warmer

                "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

                1 條回覆 最後回覆
                1
                • P 離線
                  P 離線
                  Payx
                  寫於 最後由 編輯
                  #61

                  I got :

                  QColor domicolor=dominantColor(pixi,point,size);
                  

                  The returned color is "domicolor", so i put domicolor in :

                  void fillSection(pixi, point, size, domicolor);
                  
                  1 條回覆 最後回覆
                  2
                  • VRoninV 離線
                    VRoninV 離線
                    VRonin
                    寫於 最後由 編輯
                    #62

                    sooo close!
                    http://www.cplusplus.com/doc/tutorial/functions/#void

                    "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 條回覆 最後回覆
                    1
                    • VRoninV VRonin

                      sooo close!
                      http://www.cplusplus.com/doc/tutorial/functions/#void

                      P 離線
                      P 離線
                      Payx
                      寫於 最後由 Payx 編輯
                      #63

                      I call her with just :

                      fillSection(pixi,point,size,domicolor);
                      
                      VRoninV 1 條回覆 最後回覆
                      3
                      • P Payx

                        I call her with just :

                        fillSection(pixi,point,size,domicolor);
                        
                        VRoninV 離線
                        VRoninV 離線
                        VRonin
                        寫於 最後由 編輯
                        #64

                        @Payx Bingo!

                        "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

                        1 條回覆 最後回覆
                        2
                        • P 離線
                          P 離線
                          Payx
                          寫於 最後由 編輯
                          #65

                          I try to change the rectSize with 100 x 100.

                          my first function is :

                          void MainWindow::on_push_clicked()
                          {
                          	QString fileName = QFileDialog::getOpenFileName(this,
                          	tr("Open Image"), "/", tr("Image Files (*.png *.jpg *.bmp)"));
                          	QPixmap pix(fileName);
                          	ui->label->setPixmap(pix);
                          	const QSize s = pix.size();
                          	QImage pixi = QImage(pix.toImage());
                          
                          	ui->label_2->setText( "Size: " + QString::number(s.width()) +" "+ QString::number(s.height()) );
                          
                          }
                          

                          It load an image with an explorer file.

                          But the picture dont change at all when i click on the push2

                          1 條回覆 最後回覆
                          0
                          • VRoninV 離線
                            VRoninV 離線
                            VRonin
                            寫於 最後由 VRonin 編輯
                            #66

                            I did not say you were done, just that you were on the right path.

                            from the code you posted it's clear you did not grasp scoping 100% so i'll repost the link: http://www.cplusplus.com/doc/tutorial/namespaces/#scopes

                            pix and pixi die as soon as MainWindow::on_push_clicked() terminates

                            "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 條回覆 最後回覆
                            0
                            • VRoninV VRonin

                              I did not say you were done, just that you were on the right path.

                              from the code you posted it's clear you did not grasp scoping 100% so i'll repost the link: http://www.cplusplus.com/doc/tutorial/namespaces/#scopes

                              pix and pixi die as soon as MainWindow::on_push_clicked() terminates

                              P 離線
                              P 離線
                              Payx
                              寫於 最後由 編輯
                              #67

                              @VRonin Yes but in my .h i add QImage pixi thats not correct?

                              1 條回覆 最後回覆
                              0
                              • VRoninV 離線
                                VRoninV 離線
                                VRonin
                                寫於 最後由 編輯
                                #68

                                I'm surprised your compiler doesn't yell about redefinition (I probably know why but that's not the point here). I'send you to http://www.cplusplus.com/doc/tutorial/namespaces/#scopes once again

                                "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

                                kshegunovK P 2 條回覆 最後回覆
                                0
                                • VRoninV VRonin

                                  I'm surprised your compiler doesn't yell about redefinition (I probably know why but that's not the point here). I'send you to http://www.cplusplus.com/doc/tutorial/namespaces/#scopes once again

                                  kshegunovK 離線
                                  kshegunovK 離線
                                  kshegunov
                                  Moderators
                                  寫於 最後由 編輯
                                  #69

                                  @VRonin said in Picture:

                                  I'm surprised your compiler doesn't yell about redefinition

                                  Not redefinition, shadowing, hence no yelling. :)

                                  Read and abide by the Qt Code of Conduct

                                  VRoninV 1 條回覆 最後回覆
                                  2
                                  • kshegunovK kshegunov

                                    @VRonin said in Picture:

                                    I'm surprised your compiler doesn't yell about redefinition

                                    Not redefinition, shadowing, hence no yelling. :)

                                    VRoninV 離線
                                    VRoninV 離線
                                    VRonin
                                    寫於 最後由 編輯
                                    #70

                                    @kshegunov said in Picture:

                                    shadowing

                                    The case @kshegunov is explaining is in the 3rd code block of the link above:

                                    // inner block scopes
                                    #include <iostream>
                                    using namespace std;
                                    
                                    int main () {
                                      int x = 10;
                                      int y = 20;
                                      {
                                        int x;   // ok, inner scope.
                                        x = 50;  // sets value to inner x
                                        y = 50;  // sets value to (outer) y
                                        cout << "inner block:\n";
                                        cout << "x: " << x << '\n';
                                        cout << "y: " << y << '\n';
                                      }
                                      cout << "outer block:\n";
                                      cout << "x: " << x << '\n';
                                      cout << "y: " << y << '\n';
                                      return 0;
                                    }
                                    

                                    This means I should go back to that tutorial myself

                                    "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

                                    1 條回覆 最後回覆
                                    2
                                    • VRoninV VRonin

                                      I'm surprised your compiler doesn't yell about redefinition (I probably know why but that's not the point here). I'send you to http://www.cplusplus.com/doc/tutorial/namespaces/#scopes once again

                                      P 離線
                                      P 離線
                                      Payx
                                      寫於 最後由 編輯
                                      #71

                                      @VRonin so if i want use my picture in an other function i have to declare it before my function as i did for

                                      QColor dominantColor(const QImage& image, const QPoint& topLeft, const QSize& rectSize);

                                      so i have to add a line code QImage pixi in my .cpp ?

                                      why not in my .h, and why

                                      QColor dominantColor
                                      

                                      dont work in my .h too ?

                                      1 條回覆 最後回覆
                                      0
                                      • VRoninV 離線
                                        VRoninV 離線
                                        VRonin
                                        寫於 最後由 編輯
                                        #72

                                        Ok, this has become too chatty, let's make it more structured before we both get banned.

                                        • Put dominantColor and fillSection code from either me or @mrjj at the top of your .cpp file, just below the #includes no need to declare them in advance in this case
                                        • in the private: section of your .h file add QImage m_baseImag;
                                        • in on_push_clicked load the image from file and store it in m_baseImag then use QPixmap::fromImage(m_baseImag) to display the image in the QLabel
                                        • in on_push2_clicked iterate over every 4x4 square of your picture calling the two functions:
                                        for (int i=0;i<m_baseImag.width();i+=4){
                                                   for (int j=0;j<m_baseImag.height();j+=4){
                                        fillSection(m_baseImag,QPoint(i,j),QSize(4,4),dominantColour(m_baseImag,QPoint(i,j),QSize(4,4)));
                                        }}
                                        
                                        • use QPixmap::fromImage(m_baseImag) to display the new image in another 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

                                        1 條回覆 最後回覆
                                        1
                                        • P 離線
                                          P 離線
                                          Payx
                                          寫於 最後由 Payx 編輯
                                          #73

                                          Hello,

                                          I have 0 error but it didn't work.

                                          here my code

                                          void MainWindow::on_push_clicked()
                                          {
                                          	QString fileName = QFileDialog::getOpenFileName(this,
                                          	tr("Open Image"), "/", tr("Image Files (*.png *.jpg *.bmp)"));
                                          	QPixmap pix(fileName);
                                          	ui->label->setPixmap(pix);
                                          	const QSize s = pix.size();
                                          	QImage pixi = QImage(pix.toImage());
                                          
                                          	
                                          
                                          }
                                          
                                          void MainWindow::on_push2_clicked()
                                          {
                                          	QPoint point(0,0);
                                          	QSize size(4,4);
                                          	for(int i=0;i<pixi.width();i+=4){
                                          		for(int j=0;j<pixi.height();j+=4){
                                          			fillSection(pixi,point,size,dominantColor(pixi,point,size));
                                          		}
                                          	}
                                          
                                          	QPixmap pixa=QPixmap::fromImage(pixi);
                                          
                                          	ui->label_2->setPixmap(pixa);
                                          }
                                          

                                          In my .h i declared

                                          private:
                                             Ui::MainWindow *ui;
                                             QImage pixi;
                                          

                                          pixi is the name of my picture (= m_baseImag)

                                          i display pixa (Qpix from pixi) in the same label as pixi (dont know if i can do that)

                                          1 條回覆 最後回覆
                                          0

                                          • 登入

                                          • Login or register to search.
                                          • 第一個貼文
                                            最後的貼文
                                          0
                                          • 版面
                                          • 最新
                                          • 標籤
                                          • 熱門
                                          • 使用者
                                          • 群組
                                          • 搜尋
                                          • Get Qt Extensions
                                          • Unsolved