//以下是简单的在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();
}
connect(ui->OpenImageBtn,SIGNAL(clicked()), this, SLOT(on_slotOpenImage_triggered()));