如何使用C++和Qt将QPixmap保存为文件夹中的图片
How to save a QPixmap as a picture in a folder with C++ and Qt?
我正在尝试编写一个C++函数,使用Qt GUI将所选图片保存到我的程序目录中。
到目前为止,我在QPixmap对象上使用的"保存"函数不会保存任何内容,我也不知道为什么。
这是代码:
qImage = new QPixmap(path);
QPixmap qImage2 = qImage->scaled(this->width(),this->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
qImage2.toImage();
qImage2.save(QDir::currentPath());
qDebug()<<QDir::currentPath();
有人能帮我吗?:)
-
QDir::currentPath()
返回当前工作的目录。显然,没有指定文件名本身。只需附加所需的文件名,例如:QDir::currentPath() + "/123.png"
-
CCD_ 3是返回从CCD_ 5转换而来的CCD_。实际上,它在代码中没有任何用处,请删除它或使用
QImage
。 QDir::currentPath()
返回当前工作目录,该目录不必为应用程序可执行目录。如果需要可执行目录,请改用QCoreApplication::applicationDirPath()
- 此外,正如Violet Giraffe所指出的,可能存在写入权限问题
相关文章:
- 如何将更多文件夹添加到c++include路径
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 如何在文档文件夹中创建目录
- "assimp/config.h"找不到,但它在文件夹中
- C++入门 5 版:类消息和文件夹
- Gstreamer:每 5 秒使用多文件墨水保存图像/jpeg
- 我可以在 Arduino 的库文件夹之外安装库吗?
- 使用Boost文件系统C++将具有特定扩展名的文件的名称保存在特定文件夹中
- 在 cab 应用程序卸载时将文件保存在文件夹中
- 从一个文件夹中加载文件并保存到另一个文件夹
- 特定文件夹保存和读取
- 保存文件或文件夹的时间戳
- 从文件夹中读取文件并将其保存到字符串向量中
- 将Qt DLL保存在单独的文件夹中
- 将文件保存在 %temp% 文件夹中
- c++ Qt和WinExec -保存CMD输出文件在特定的文件夹
- 如何使用C++和Qt将QPixmap保存为文件夹中的图片
- 在使用mkdir()创建一个文件夹后,我如何让程序将文件和其他信息保存到新文件夹中?