图片静态展示

图片静态展示程序,包含选择文件夹路径,旋转,放大缩小,拖动,幻灯片播放,上一张下一张等,程序使用QT实现。

程序下载地址:

图片静态展示,包含选择文件夹路径,旋转等资源-CSDN文库

用户选择路径

cpp 复制代码
//利用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中。

cpp 复制代码
QPixmap dest = QPixmap::fromImage(image.scaled(ui->label->size() * zoomValue, Qt::KeepAspectRatio, Qt::SmoothTransformation));
ui->label->setPixmap(dest);

图片旋转

利用QT的QTransform来确定旋转角度,QImage::transformed进行变换。

cpp 复制代码
QTransform transform;
transform.rotate(-90);//左旋
transform.rotate(90);//右旋
image = image.transformed(transform);

图片放大缩小

利用鼠标滚轮来确定放大缩小倍数。

cpp 复制代码
wheelEvent(QWheelEvent *event)
{
    int value = event->delta();
    if (value > 0) {
        if (zoomValue < 1) {
            zoomValue += 0.05;
        }
    } 
    else if (zoomValue > 0.2) 
    {
        zoomValue -= 0.05;
    }
}
相关推荐
樱木Plus1 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit3 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_4 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星4 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛6 天前
delete又未完全delete
c++
端平入洛7 天前
auto有时不auto
c++
哇哈哈20218 天前
信号量和信号
linux·c++
多恩Stone8 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马8 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝8 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode