QT生成ICO文件

生成ICO文件

cpp 复制代码
#include <QApplication>
#include <QImage>
#include <QIcon>
#include <QFile>
#include <QDebug>
#include <QPixmap>

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    // 读取图片文件
    QImage image("D:\\MultiChannelVideo\\code\\src\\115_xviewer_test\\img\\logo_150_40.png"); // 替换为您的图片文件路径

    if (image.isNull()) {
        qDebug() << "Failed to load image.";
        return 1;
    }

    // 保存图像为.ico文件
    QString filePath = "D:\\MultiChannelVideo\\code\\src\\115_xviewer_test\\img\\output_icon.ico"; // 保存的.ico文件路径
    QPixmap pixmap = QPixmap::fromImage(image);
    if (pixmap.save(filePath, "ICO")) {
        qDebug() << "Icon saved to" << filePath;
    }
    else {
        qDebug() << "Failed to save icon.";
    }

    return app.exec();
}

相关推荐
Lhan.zzZ8 小时前
Qt WebEngineView 在 Linux 上无法加载网页:从“看不见 HTML“到“禁用沙箱“
linux·c++·qt
Quz16 小时前
QML TabBar 标签栏交互效果合集
qt·动画·qml
zhanghaha131419 小时前
Qt 工程实例:逐词逐句保姆级讲解
qt
架构师伯子明1 天前
QT+OpenGL(3):FBO离屏渲染
开发语言·qt
mengzhi啊2 天前
把数据存入sql数据库。qt,c++。
数据库·sql·qt
mengzhi啊2 天前
SerialPortItem对串口再封装一层,省去一些常用的步骤,不用每次都去写类
qt
用户8334423966142 天前
从批量操作到任务中心,再到现场工作台:DeviceForge v2.10—v2.12 完整演进
qt
宛 禾2 天前
Qt 控件入门:QLabel 从拖拽到对象树,一篇讲透
c++·qt·学习
打工仔折腾 AI3 天前
Qt网络编程实战:UDP、TCP到HTTP的落地经验与选型
网络·人工智能·后端·python·qt·udp·ai agent 实战
Lhan.zzZ3 天前
Linux + Qt/QML:解决 QtQuick.VirtualKeyboard.Plugins 模块加载失败与环境变量配置
linux·数据库·qt