Picture
-
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
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); }