Solved Picture
-
-
-
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
-
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 ?
-
Getting warmer and warmer
-
I got :
QColor domicolor=dominantColor(pixi,point,size);
The returned color is "domicolor", so i put domicolor in :
void fillSection(pixi, point, size, domicolor);
-
-
I call her with just :
fillSection(pixi,point,size,domicolor);
-
@Payx Bingo!
-
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 -
@VRonin Yes but in my .h i add QImage pixi thats not correct?
-
I'm surprised your compiler doesn't yell about redefinition (I probably know why but that's not the point here). I'send you to http://www.cplusplus.com/doc/tutorial/namespaces/#scopes once again
-
-
@kshegunov said in Picture:
shadowing
The case @kshegunov is explaining is in the 3rd code block of the link above:
// inner block scopes #include <iostream> using namespace std; int main () { int x = 10; int y = 20; { int x; // ok, inner scope. x = 50; // sets value to inner x y = 50; // sets value to (outer) y cout << "inner block:\n"; cout << "x: " << x << '\n'; cout << "y: " << y << '\n'; } cout << "outer block:\n"; cout << "x: " << x << '\n'; cout << "y: " << y << '\n'; return 0; }
This means I should go back to that tutorial myself
-
@VRonin so if i want use my picture in an other function i have to declare it before my function as i did for
QColor dominantColor(const QImage& image, const QPoint& topLeft, const QSize& rectSize);
so i have to add a line code QImage pixi in my .cpp ?
why not in my .h, and why
QColor dominantColor
dont work in my .h too ?
-
Ok, this has become too chatty, let's make it more structured before we both get banned.
- Put
dominantColor
andfillSection
code from either me or @mrjj at the top of your .cpp file, just below the#include
s no need to declare them in advance in this case - in the
private:
section of your .h file addQImage m_baseImag;
- in on_push_clicked load the image from file and store it in
m_baseImag
then useQPixmap::fromImage(m_baseImag)
to display the image in theQLabel
- in
on_push2_clicked
iterate over every 4x4 square of your picture calling the two functions:
for (int i=0;i<m_baseImag.width();i+=4){ for (int j=0;j<m_baseImag.height();j+=4){ fillSection(m_baseImag,QPoint(i,j),QSize(4,4),dominantColour(m_baseImag,QPoint(i,j),QSize(4,4))); }}
- use
QPixmap::fromImage(m_baseImag)
to display the new image in anotherQLabel
- Put
-
Hello,
I have 0 error but it didn't work.
here my code
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()); } void MainWindow::on_push2_clicked() { QPoint point(0,0); QSize size(4,4); for(int i=0;i<pixi.width();i+=4){ for(int j=0;j<pixi.height();j+=4){ fillSection(pixi,point,size,dominantColor(pixi,point,size)); } } QPixmap pixa=QPixmap::fromImage(pixi); ui->label_2->setPixmap(pixa); }
In my .h i declared
private: Ui::MainWindow *ui; QImage pixi;
pixi is the name of my picture (= m_baseImag)
i display pixa (Qpix from pixi) in the same label as pixi (dont know if i can do that)
-
Hi
Good work.
in here
void MainWindow::on_push_clicked()
{
......
QImage pixi = QImage(pix.toImage()); // This looks like a local variable? ( die by scope)
}Did you mean to use the one from .H ?
so
pixi = QImage(pix.toImage());