图片静态展示程序,包含选择文件夹路径,旋转,放大缩小,拖动,幻灯片播放,上一张下一张等,程序使用QT实现。
程序下载地址:
图片静态展示,包含选择文件夹路径,旋转等资源-CSDN文库
用户选择路径
//利用QFileDialog返回用户选择的路径
auto path = QFileDialog::getExistingDirectory(this, "请选择图片目录");
QDir dir(path);//获取图片名auto imgList = dir.entryList(QStringList()<<"*.png" << "*.bmp" << "*.jpg" << "*.tif" << "*.gif");
if (imgList.length() == 0)return;//存储此文件夹下的图片文件
for (auto file : imgList) {fileList.append(path + "/" + file);
}
图片显示
根据当前图片的index,在paintEvent中显示图片,zoomValue是放大倍数,图片显示在label中。
QPixmap dest = QPixmap::fromImage(image.scaled(ui->label->size() * zoomValue, Qt::KeepAspectRatio, Qt::SmoothTransformation));
ui->label->setPixmap(dest);
图片旋转
利用QT的QTransform来确定旋转角度,QImage::transformed进行变换。
QTransform transform;
transform.rotate(-90);//左旋
transform.rotate(90);//右旋
image = image.transformed(transform);
图片放大缩小
利用鼠标滚轮来确定放大缩小倍数。
wheelEvent(QWheelEvent *event)
{int value = event->delta();if (value > 0) {if (zoomValue < 1) {zoomValue += 0.05;}} else if (zoomValue > 0.2) {zoomValue -= 0.05;}
}