Picture
-
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)
-
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
@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 }
-
@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 }
@kshegunov
sorry i lost youin 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
-
@kshegunov
sorry i lost youin 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
-
@kshegunov
sorry i lost youin 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
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.
-
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
-
-
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 ?
-
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 ?
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
-
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
-
-
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
-
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
andpixi
die as soon asMainWindow::on_push_clicked()
terminates -
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
andpixi
die as soon asMainWindow::on_push_clicked()
terminates