QT中循環顯示圖片和簡單的顯示圖片


請關注我的github

https://github.com/linqiaozhou
以下實例代碼不久后將會上傳到我的github
這是我最近一個項目中的部分代碼
//以下是簡單的在QT中顯示圖片的代碼
this->imageOrg = new QImage();

    if(fileName != "")

    {

        if(imageOrg->load(fileName))

        {

 

            this->scene = new QGraphicsScene;

            *imageOrg=imageOrg->scaled(ui->View1->width()-10,ui->View1->height()-10,Qt::IgnoreAspectRatio);

            scene->addPixmap(QPixmap::fromImage(*imageOrg));

            ui->View1->setScene(scene);

           //ui->graphicsView->resize(image->width() + 10, image->height() + 10);

            ui->View1->show();

 

        }

 

    }

}

 

//循環顯示圖片的代碼
void  MainWindow::autoplay()    //自動播放函數
{
    QString fileName = QFileDialog::getOpenFileName(
               this, "Open Image File",
              ".",
            "Image files (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *.xbm *.xpm);;All files (*.*)");
    if(fileName != "")
    {
        ui->vedioLabel->setPixmap(fileName);
        update();
    }
 
    //以下步驟得到上層路徑並求得圖像序列號
    int len=fileName.length()-1;
    while(fileName[len]!='/')
    {
      len--;
    }
    stringstream os;
    string s=fileName.toStdString();
    os<<s[len+1];
    os<<s[len+2];
    os>>indexVedio;
    os.str("");
    QString fileDir(len);
    for(int i=0;i
    {
        fileDir[i]=fileName[i];
    }
 
    imgDirVideo.setPath(fileDir);
    QStringList filter ;
    filter << "*.jpg" << "*.bmp" << "*.jpeg" << "*.png" << "*.xpm" ;
    imgListVideo =imgDirVideo.entryList(filter, QDir::Files |QDir::NoSymLinks,QDir::Name) ;
 
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(cdPicture()));
   // QString framRate=ui->text3->toPlainText();
    timer->start(100);//定時器,每隔100MS秒刷新
 
}
 
 
//下面的子函數更改顯示的幀數
void MainWindow::cdPicture()
{
   //pixImage.load(imgDirVideo.absolutePath() + QDir::separator()+ imgListVideo.at(1));
 
   indexVedio++;
   if(indexVedio==MaxIndex)
   {
     if (timer->isActive())
     {
         timer->stop();
 
     }
 
     QMessageBox::information(this,"End","The Last Frame");
     return ;
   }
   ui->vedioLabel->setPixmap(imgDirVideo.absolutePath() + QDir::separator()+ imgListVideo.at(indexVedio));
   update();
}
 

 

 
QT中信號與槽的簡單示例:
private slots:

      void on_slotOpenImage_triggered(); //信號槽

connect(ui->OpenImageBtn,SIGNAL(clicked()), this, SLOT(on_slotOpenImage_triggered()));

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM