Skip to content

Commit

Permalink
ensure .png extension so QPixmap save works, re #8482
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed Nov 20, 2014
1 parent 70d620a commit 80da929
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Expand Up @@ -1125,6 +1125,28 @@ void SliceViewer::copyImageToClipboard()
QApplication::clipboard()->setImage(pix, QClipboard::Clipboard);
}

/**
* Adds .png extension if not already included
*
* @param filename :: a file name to save an (png) image
* @return input file name with '.png' appended if needed
**/
QString SliceViewer::ensurePngExtension(const QString& fname) const
{
const QString goodExt = "png";

QString res = fname;
qDebug() << "fname: " << fname;
qDebug() << "res before: " << res;
qDebug() << "suffix: " << QFileInfo(fname).suffix();
if (QFileInfo(fname).suffix() != goodExt)
{
res = res + "." + goodExt;
}
qDebug() << "returning: " << res;
return res;
}

//------------------------------------------------------------------------------------
/** Save the rendered 2D slice to an image file.
*
Expand All @@ -1147,10 +1169,13 @@ void SliceViewer::saveImage(const QString & filename)
else
fileselection = filename;

// append '.png' if needed
QString finalName = ensurePngExtension(fileselection);

// Create the image
QPixmap pix = this->getImage();
// And save to the file
pix.save(fileselection);
pix.save(finalName);

}

Expand Down

0 comments on commit 80da929

Please sign in to comment.