选择文件保存路径有两种逻辑:
1.先选择文件保存路径后拍照;
2.先拍照后选择路径保存该bufframe
逻辑1的实现方法:
ui界面
点击获取保存路径PushButton,
void suCam::on_pushButton_fileChoose_clicked()
{
QString srcDirPath = QFileDialog::getExistingDirectory(
this, "choose src Directory",
"/");
if (srcDirPath.isEmpty())
{
return;
}
else
{
qDebug() << "srcDirPath=" << srcDirPath;
srcDirPath += "/";
}
}
获取保存地址后,自动保存代码如下:
//Auto Save
void HamamatsuCam::SaveSequenceImg(QImage image, int nframe)
{
std::string m_path = srcDirPath.toStdString();
std::string path = m_path +std::to_string(nframe) + ".bmp";
QString SavePath = QString::fromStdString(m_path);
QString SequenceSavePath = QString::fromStdString(path);
image.save(SequenceSavePath,"tif",100); //类型
}
逻辑2的实现方法:
在已经获取一张图片的bufframe的前提下,选择保存:
//BTN-Save Snap image
void suCam::on_pushButton_save_clicked()
{
//获取保存路径
if(snap_img.isNull())return;
_TempPath = QCoreApplication::applicationDirPath();//.exe项目文件所在目录
dtCurtime = QDateTime::currentDateTime(); //设置当前时间为保存时间
_TempPath = _TempPath + "//Image//" + dtCurtime.toString("yyyyMMddhhmmss"); //保存名称为path + image(?) + 日期年y月M日d时h分m秒s
strFileName = QFileDialog::getSaveFileName(this,tr("Save Picture"), //类函数QFileDiaLog:获取文件路径//getSaveFileName:获取保存文件名字
_TempPath,
"PNG(*.png);;JPG(*.jpg);;BMP(*.bmp);;TIF(*.tif)");
if(!strFileName.isNull())
{
int nIndex = strFileName.lastIndexOf('.');//寻找‘.’符号在字符串中的id
nIndex++;
int nLen = strFileName.length()-nIndex;
strSuffix = strFileName.right(nLen);//截取‘.’符号后面的字符串,这是为了获取用户选择的文件后缀名
snap_img.save(strFileName,strSuffix.toUpper().toUtf8(),100);//保存图片
}
}