diff --git a/src/app/composer/qgscomposer.cpp b/src/app/composer/qgscomposer.cpp index aad47864a18f..4853f0a533de 100644 --- a/src/app/composer/qgscomposer.cpp +++ b/src/app/composer/qgscomposer.cpp @@ -76,6 +76,7 @@ #include #include #include +#include #include #include #include @@ -2069,7 +2070,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode ) outputFilePath = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix(); } - saveOk = image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() ); + saveOk = saveImage( image, outputFilePath, fileNExt.second ); if ( !saveOk ) { @@ -2269,7 +2270,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode ) imageFilename = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix(); } - bool saveOk = image.save( imageFilename, format.toLocal8Bit().constData() ); + bool saveOk = saveImage( image, imageFilename, format ); if ( !saveOk ) { QMessageBox::warning( this, tr( "Atlas processing error" ), @@ -2311,6 +2312,16 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode ) } } +bool QgsComposer::saveImage( const QImage &img, const QString &imageFilename, const QString &imageFormat ) +{ + QImageWriter w( imageFilename, imageFormat.toLocal8Bit().constData() ); + if ( imageFormat.compare( "tiff", Qt::CaseInsensitive ) == 0 || imageFormat.compare( "tif", Qt::CaseInsensitive ) == 0 ) + { + w.setCompression( 1 ); //use LZW compression + } + return w.write( img ); +} + void QgsComposer::on_mActionExportAtlasAsSVG_triggered() { QgsComposition::AtlasMode previousMode = mComposition->atlasMode(); diff --git a/src/app/composer/qgscomposer.h b/src/app/composer/qgscomposer.h index 0888947ab8df..8422e9be44c2 100644 --- a/src/app/composer/qgscomposer.h +++ b/src/app/composer/qgscomposer.h @@ -484,6 +484,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase QgsPanelWidget *createItemWidget( QgsComposerItem *item ); + /*Saves image to file, possibly using format specific options (e.g. LZW compression for tiff) + @param img the image to save + @param imageFileName output file path + @param imageFormat format string + @param return true in case of success*/ + static bool saveImage( const QImage &img, const QString &imageFilename, const QString &imageFormat ); + QgsAppComposerInterface *mInterface = nullptr; //! Labels in status bar which shows current mouse position