Home > database >  How to print current pixel of an QImage?
How to print current pixel of an QImage?

Time:04-15

I have an RGB888 format qImage defined as follows:

int sizeX = 300; int sizeY = 300;
QImage img = QImage(sizeX, sizeY, QImage::Format_RGB888);

I wish to print current pixel of img one by one. So, I followed the example here:`

 for(int i=0; i<sizeX; i  ){
 for(int j=0; j<sizeY; j  ){
       img.setPixel(i, j, qRgb(rand()%6, rand()%6, rand()%6));
    }
}
QGraphicsScene *graphic = new QGraphicsScene(this);
graphic->addPixmap(QPixmap::fromImage(img));
ui->graphicsView->setScene(graphic);

But it prints the whole QImage. I want to print one by one. Thanks. Best regards.

CodePudding user response:

As JarMan commented, you are looking for "animation".

Drawing pixel by pixel, and updating the UI for every pixel, may use animation solution as described in the enter image description here

  • Related