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. Picture
Forum Updated to NodeBB v4.3 + New Features

Picture

Scheduled Pinned Locked Moved Solved General and Desktop
82 Posts 7 Posters 51.8k 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.
  • 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 Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by
    #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 Reply Last reply
    1
    • P Offline
      P Offline
      Payx
      wrote on last edited by
      #82

      Thank you very much !

      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