加载图片作为例子:
QImage image;
image.load("C:\\Users\\18035\\Desktop\\pic.jpg");
QPixmap pixx = QPixmap::fromImage(image);
点击保存按钮之后的响应函数里面这么写:
QString strFileName = QFileDialog::getSaveFileName(this,tr("Save Picture"),"","PNG(*.png);;JPG(*.jpg);;BMP(*.bmp)");
if(!strFileName.isNull())
{
int nIndex = strFileName.lastIndexOf('.');//寻找‘.’符号在字符串中的id
nIndex++;
int nLen = strFileName.length()-nIndex;
QString strSuffix = strFileName.right(nLen);//截取‘.’符号后面的字符串,这是为了获取用户选择的文件后缀名
pixx.save(strFileName,strSuffix.toUpper().toUtf8());//保存图片
}
这里面最主要的就是“PNG( .png);;JPG( .jpg);;BMP(*.bmp)”这段字符,就决定了用户可选择的种类