QT 利用QPixmap复制图片

239 阅读1分钟

记录一下,今天忘记这个用法了,想查资料不知道从哪里查起,所以记录一下。代码如下,首先使用QFileDialog::getSaveFileName()获取保存路径,这里我是用时间作为命名规则,即获取当前时间作为文件名称。然后使用QPixmap打开一张图片,这里我是用本地图片,路径为"./pix001.jpg",然后使用save()函数即可完成复制,这样就将图片"./pix001.jpg"复制到fileName了。

    QDateTime current_time =QDateTime::currentDateTime();
    QString strTime = current_time.toString("yy-MM-dd-hh-mm-ss");
    //保存文件对话框
    QString fileName = QFileDialog::getSaveFileName(NULL,QObject::tr("Save Image"),
                                                    "./image_file/UseImage/"+strTime+".jpg",
                                                    QObject::tr("*.jpg"));
    QPixmap *cur_pictrue()=new QPixmap("./pix001.jpg");
    cur_pictrue->save(fileName);