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

    Ok after long hours, i fixed it.

    Thank you very much for your time in my project.

    But i have a little question :

    In the code it only returns Red, Blue or Green.

    Do you have a function who return a lot of color, like if in my rect the most principal color is grey (for example) what could i do to add a lot of color ?

    At the end i will have a picture more pixelated but that i can recognize

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

    I suggest you average the color in the rectangle, e.g. (thanks to @VRonin for the scaffolding):

    QColor dominantColour(const QImage & image,const QPoint & topLeft, const QSize & rectSize)
    {
        qint32 averageRed = 0, averageGreen = 0, averageBlue = 0;
    
        const qint32 maxX = qMin<qint32>(image.width(), topLeft.x() + rectSize.width());
        const qint32 maxY = qMin<qint32>(image.height(), topLeft.y() + rectSize.height());
        for (qint32 y = topLeft.y(); y < maxY; y++)  {
            for (qint32 x = topLeft.x(); x < maxX; x++)   {
                QRgb pixel = image.pixel(x, y);
                
                averageRed += qRed(pixel);
                averageGreen += qGreen(pixel);
                averageBlue += qBlue(pixel);
            }
        }
    
        qint32 n = rectSize.width() * rectSize.height();
    
        Q_ASSERT(n);
        if (n <= 0)
            return Qt::black;
    
        return QColor(averageRed / n, averageGreen / n, averageBlue / n);
    }
    

    Read and abide by the Qt Code of Conduct

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

      Thank you very much !

      1 條回覆 最後回覆
      0

      • 登入

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