PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Qt: Skaliertes Pixmap als *.bmp speichern



melanie
19-01-2011, 14:06
Hallo,

ich würde gerne ein QPixmap (eines QLabels), dessen Größe und Aspektverhältnis ich mit resize(width, height) geändert habe, als bmp speichern. Leider bekomme ich das nicht hin. Es wird immer das nicht skalierte/verzerrte Bild gespeichert.
Weiß jemand einen Rat?
Danke :D

locus vivendi
19-01-2011, 16:07
Das folgende Programm funktioniert bei mir so wie ich es erwarten würde:


#include "QtCore/QObject"
#include "QtGui/QApplication"
#include "QtGui/QLabel"
#include "QtGui/QPixmap"
#include "QtGui/QPushButton"
#include "QtGui/QWidget"

class mainwindow : public QWidget
{
Q_OBJECT
public:
mainwindow() : label("Text Text ABC", this), button("Save pixmap to file and quit!", this) {
label.resize(400, 300);
button.move(0, 300);

QObject::connect(&button, SIGNAL(clicked()), this, SLOT(save_file()));
QObject::connect(&button, SIGNAL(clicked()), qApp, SLOT(quit()));
}

public slots:
void save_file() {
QPixmap pix(label.size());
label.render(&pix);
pix.save("save_label.output.bmp");
}

private:
QLabel label;
QPushButton button;
};

int main( int argc, char *argv[] ) {
QApplication app(argc, argv);

mainwindow app_window;
app_window.show();

return app.exec();
}

melanie
21-01-2011, 10:45
Hallo locus vivendi,

vielen Dank für die Lösung meines Problems :D
Funktioniert super!