1 //BTN-Save Snap image
2 void suCam::on_pushButton_save_clicked()
3 {
4 //获取保存路径
5 if(snap_img.isNull())return;
6 _TempPath = QCoreApplication::applicationDirPath();//.exe项目文件所在目录
7 dtCurtime = QDateTime::currentDateTime(); //设置当前时间为保存时间
8 _TempPath = _TempPath + "//Image//" + dtCurtime.toString("yyyyMMddhhmmss"); //保存名称为path + image() + 日期年y月M日d时h分m秒s
9 strFileName = QFileDialog::getSaveFileName(this,tr("Save Picture"), //类函数QFileDiaLog:获取文件路径//getSaveFileName:获取保存文件名字
10 _TempPath,
11 "PNG(*.png);;JPG(*.jpg);;BMP(*.bmp);;TIF(*.tif)");
12 if(!strFileName.isNull())
13 {
14 int nIndex = strFileName.lastIndexOf('.');//寻找‘.’符号在字符串中的id
15 nIndex++;
16 int nLen = strFileName.length()-nIndex;
17 strSuffix = strFileName.right(nLen);//截取‘.’符号后面的字符串,这是为了获取用户选择的文件后缀名
18 snap_img.save(strFileName,strSuffix.toUpper().toUtf8(),100);//保存图片
19 }
20 }