跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • 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.4k 瀏覽 3 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • P Payx

    Thanks both of you, it works !
    The problem i think is that i don't understand english very well, that's my problem.

    So if i understood well,

    i will have :

    void MainWindow::on_push2_clicked()
    {
    
    	QColor dominantColor(const QImage& pixi, const QPoint& topLeft, const QSize& rectSize);
    	void fillSection(QImage& pixi, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);
    
    }
    

    I check what the code do, if i'm right i have to define the
    rectSize.height()
    and rectSize.width()

    and last question
    when i have

    for(int x = topLeft.x(); x < maxRight; ++x) {
    		for(int y = topLeft.y(); x < maxBottom; ++x) {
    

    in the second line, it's not 'y' the variable who change?

    and

    const int maxRight = qMin(pixi.width(), topLeft.x() + rectSize.width());
    for(int x = topLeft.x(); x < maxRight; ++x) {
    

    if we define rectSize (4*4) the for will go from 0 to 4 only no ? we need to change the rectsize at the end of the for no ?

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

    @Payx said in Picture:

    i will have :
    void MainWindow::on_push2_clicked()
    {

    QColor dominantColor(const QImage& pixi, const QPoint& topLeft, const QSize& rectSize);
    void fillSection(QImage& pixi, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);

    }

    this makes no sense

    in the second line, it's not 'y' the variable who change?

    yes, I corrected it but @mrjj was faster and copied the code before I could amend it

    the for will go from 0 to 4 only no ?

    no, it will go from 0 to 3, 4 pixels

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

      @Payx said in Picture:

      i will have :
      void MainWindow::on_push2_clicked()
      {

      QColor dominantColor(const QImage& pixi, const QPoint& topLeft, const QSize& rectSize);
      void fillSection(QImage& pixi, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);

      }

      this makes no sense

      in the second line, it's not 'y' the variable who change?

      yes, I corrected it but @mrjj was faster and copied the code before I could amend it

      the for will go from 0 to 4 only no ?

      no, it will go from 0 to 3, 4 pixels

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

      @VRonin

      no, it will go from 0 to 3, 4 pixels

      Yes but if my picture is composed by 500 pixels, it will go from 0 to 3 pixels, and thats it, so i have to increase at the end of my "for" no ?

      this makes no sense

      When i want to call a function i have to write :

      fillSection();

      but as i said i got an error.

      so i change to fillSection(QImage& pixi, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);

      why this makes no sense?

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

        @Payx said in Picture:

        Yes but if my picture is composed by 500 pixels, it will go from 0 to 3 pixels, and thats it, so i have to increase at the end of my "for" no ?

        what would you do?

        @Payx said in Picture:

        why this makes no sense?

        www.cplusplus.com/doc/tutorial/functions/

        www.cplusplus.com/doc/tutorial/classes/

        "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

          @Payx said in Picture:

          Yes but if my picture is composed by 500 pixels, it will go from 0 to 3 pixels, and thats it, so i have to increase at the end of my "for" no ?

          what would you do?

          @Payx said in Picture:

          why this makes no sense?

          www.cplusplus.com/doc/tutorial/functions/

          www.cplusplus.com/doc/tutorial/classes/

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

          @VRonin I got rectSize = 4*4

          the function will calculate the color in the rect 44, if my picture is 500500, i have to increase at the end of my "for" the rectSize.

          like say that my maxRight isnt

          qMin(pixi.width(), topLeft.x() + rectSize.width());
          

          anymore

          and it's like qMin(pixi.width(), rectSize.width()+4)

          and at the end of my for i will add a line to increase again and again the maxRight

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

            those to functions are designed to work on a single 4x4 area, you need to build something around them to make them work over the whole picture

            "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
              寫於 最後由 編輯
              #48

              Thanks for your link obviously what i need.

              so i replace : i got

              QColor dominantColor(pixi,point,size);
              

              and i define pixi as my image (in mainwindow.h)
              and QPoint point(0,0);
              and QSize size(4,4); thats correct ?

              but i block for the QColor in void fillSection(QImage& image, const QPoint& topLeft, const QSize& rectSize, const QColor& colour)

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

                @Payx said in Picture:

                i will have :
                void MainWindow::on_push2_clicked()
                {

                QColor dominantColor(const QImage& pixi, const QPoint& topLeft, const QSize& rectSize);
                void fillSection(QImage& pixi, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);

                }

                this makes no sense

                in the second line, it's not 'y' the variable who change?

                yes, I corrected it but @mrjj was faster and copied the code before I could amend it

                the for will go from 0 to 4 only no ?

                no, it will go from 0 to 3, 4 pixels

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

                @VRonin said in Picture:

                @Payx said in Picture:

                i will have :

                void MainWindow::on_push2_clicked()
                {
                   QColor dominantColor(const QImage& pixi, const QPoint& topLeft, const QSize& rectSize);
                   void fillSection(QImage& pixi, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);
                }
                

                this makes no sense

                It's valid C++, although highly unusual. Consider this:

                void userFunction1()
                {
                    int x;
                    testFunc(x);  //< Compile error: undeclared identifier testFunc
                }
                
                void userFunction2()
                {
                    void testFunc(int &);
                
                    int x;
                    testFunc(x); //< We are okay
                }
                
                void testFunc(int & z)
                {
                    z = 0;
                }
                

                C++ forbids function definitions to appear inside function bodies, but not declarations. On the other hand, class declarations and class definitions are valid inside functions, e.g.:

                void terribleToReadFunction()
                {
                    struct  {
                        int memberOfAnonymous() const
                        {
                            return 0;
                        }
                    } inst;
                
                    int z = inst.memberOfAnonymous(); //< z is 0
                }
                

                Read and abide by the Qt Code of Conduct

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

                  @VRonin said in Picture:

                  @Payx said in Picture:

                  i will have :

                  void MainWindow::on_push2_clicked()
                  {
                     QColor dominantColor(const QImage& pixi, const QPoint& topLeft, const QSize& rectSize);
                     void fillSection(QImage& pixi, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);
                  }
                  

                  this makes no sense

                  It's valid C++, although highly unusual. Consider this:

                  void userFunction1()
                  {
                      int x;
                      testFunc(x);  //< Compile error: undeclared identifier testFunc
                  }
                  
                  void userFunction2()
                  {
                      void testFunc(int &);
                  
                      int x;
                      testFunc(x); //< We are okay
                  }
                  
                  void testFunc(int & z)
                  {
                      z = 0;
                  }
                  

                  C++ forbids function definitions to appear inside function bodies, but not declarations. On the other hand, class declarations and class definitions are valid inside functions, e.g.:

                  void terribleToReadFunction()
                  {
                      struct  {
                          int memberOfAnonymous() const
                          {
                              return 0;
                          }
                      } inst;
                  
                      int z = inst.memberOfAnonymous(); //< z is 0
                  }
                  
                  P 離線
                  P 離線
                  Payx
                  寫於 最後由 編輯
                  #50

                  @kshegunov
                  sorry i lost you

                  in my

                  void MainWindow::on_push2_clicked()
                  {
                  	QPoint point(0,0);
                  	QSize size(4,4);
                  	QColor dominantColor(pixi,point,size);
                  
                  }
                  

                  i try this i give what function needed and i declared point and size before

                  mrjjM kshegunovK 2 條回覆 最後回覆
                  0
                  • P Payx

                    @kshegunov
                    sorry i lost you

                    in my

                    void MainWindow::on_push2_clicked()
                    {
                    	QPoint point(0,0);
                    	QSize size(4,4);
                    	QColor dominantColor(pixi,point,size);
                    
                    }
                    

                    i try this i give what function needed and i declared point and size before

                    mrjjM 離線
                    mrjjM 離線
                    mrjj
                    Lifetime Qt Champion
                    寫於 最後由 mrjj 編輯
                    #51

                    @Payx said in Picture:
                    almost correct.

                    void MainWindow::on_push2_clicked()
                    {
                    QPoint point(0,0);
                    QSize size(4,4);
                    QColor domicolor=dominantColor(pixi,point,size); // where does pixi come from? its in .h?

                    }

                    1 條回覆 最後回覆
                    2
                    • P Payx

                      @kshegunov
                      sorry i lost you

                      in my

                      void MainWindow::on_push2_clicked()
                      {
                      	QPoint point(0,0);
                      	QSize size(4,4);
                      	QColor dominantColor(pixi,point,size);
                      
                      }
                      

                      i try this i give what function needed and i declared point and size before

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

                      @Payx said in Picture:

                      sorry i lost you

                      No, it's me who lost you. I was commenting on @VRonin's remark about your code. However, this:

                      QColor dominantColor(pixi,point,size);
                      

                      is neither a function call, nor is it a function declaration. The compiler will interpret this as a variable and will throw "unknown conversion from type X to type Y" errors. You should carefully read @VRonin's link on functions - what is a declaration, what is a definition and how to put it all together. Otherwise you are in for a terrible time, Qt or otherwise.

                      Kind regards.

                      Read and abide by the Qt Code of Conduct

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

                        I have to declare my function,
                        say what they do
                        and call it.

                        I say in my .cpp what she does :

                        QColor dominantColor(const QImage& image, const QPoint& topLeft, const QSize& rectSize) {
                        // calculate start stop values for the rect
                        	 const int maxRight = qMin(image.width(), topLeft.x() + rectSize.width());
                        	const int maxBottom = qMin(image.height(), topLeft.y() + rectSize.height());
                        	QVector<QColor> coloursList; // this is a list of all colors seen!
                        	for(int x = topLeft.x(); x < maxRight; ++x) {
                        		for(int y = topLeft.y(); y < maxBottom; ++y) {
                        			coloursList << image.pixelColor(x, y); // store all colors seen in this Rect
                        		}
                        	}
                        
                        	// these are functions that count (accumulate) how many times RED, GREEN and blue been used ( using the list from before)
                        	const qint64 sumRed = std::accumulate(coloursList.constBegin(), coloursList.constEnd(), 0, [](qint64 strt,  const QColor & val)->qint64 {return strt + val.red();});
                        	const qint64 sumGreen = std::accumulate(coloursList.constBegin(), coloursList.constEnd(), 0, [](qint64 strt, const QColor & val)->qint64 {return strt + val.green();});
                        	const qint64 sumBlue = std::accumulate(coloursList.constBegin(), coloursList.constEnd(), 0, [](qint64 strt, const QColor & val)->qint64 {return strt + val.blue();});
                        	// now we check out which is most used
                        	if(sumRed >= sumGreen  && sumRed >= sumBlue)
                        		return Qt::red;
                        	if(sumGreen  >= sumBlue)
                        		return Qt::green;
                        	return Qt::blue;
                        }
                        

                        I call her and i stock the result in a QColor

                        void MainWindow::on_push2_clicked()
                        {
                        	QPoint point(0,0);
                        	QSize size(4,4);
                        	QColor domicolor=dominantColor(pixi,point,size);
                        // pixi is my image declared in .h with QImage pixi;
                        
                        }
                        

                        the problem that i dont know where i can declare her. I try every possibilities

                        1 條回覆 最後回覆
                        0
                        • 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

                                          • 登入

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