bool writeTempImage(QString &tmpImgFilename, const QImage &image)
{
    const int IMG_COMPRESSION = 9; // min:0, max:9

    tmpImgFilename = QDir::tempPath() + QDir::separator() + "tmpLvkImg.png";

    if (QFile::exists(tmpImgFilename) && !QFile::remove(tmpImgFilename)) {
        qDebug() << "Could not remove temp file" << tmpImgFilename;
        return false;
    }

    QImageWriter imgWriter(tmpImgFilename, QByteArray("png"));
    imgWriter.setCompression(IMG_COMPRESSION);
    imgWriter.write(image);

    return true;
}
Esempio n. 2
0
bool KSnapshotObject::saveImage( QIODevice *device, const QByteArray &format )
{
    QImageWriter imgWriter( device, format );

    if ( !imgWriter.canWrite() ) {
	qDebug() << "Cannot write format " << format;
	return false;
    }

    // For jpeg use 85% quality not the default
    if ( 0 == qstricmp(format.constData(), "jpeg") || 0 == qstricmp(format.constData(), "jpg") ) {
	imgWriter.setQuality( 85 );
    }

    if ( !title.isEmpty() )
	imgWriter.setText( QObject::tr("Title"), title );
    if ( !windowClass.isEmpty() )
	imgWriter.setText( QObject::tr("Window Class"), windowClass );

    QImage snap = snapshot.toImage();
    return imgWriter.write( snap );
}