hvengel
16th January 2008, 01:25
I am creating a QImage and I would like to save it to disk. But the QImage::save() always return false and no image is saved. The image is valid since I am displaying it in my Widget at the time I try to save it. My code looks like this:
QPainter painter(this);
QImage backGround;
painter.setRedirected (this, &backGround, QPoint(0, 0));
painter.setWindow( 0, 0, pixcols - 1, pixrows - 1);
// bunch of painter commands
painter.setRedirected (&backGround, this, QPoint(0, 0));
QString file = "image.png";
if(backGround.save(file, "PGN", -1))
qDebug("it worked");
else
qDebug("it didn't work");
painter.setWindow( 0, 0, pixcols - 1, pixrows - 1);
QRect rect(0, 0, pixcols - 1, pixrows - 1);
painter.drawImage(rect, backGround, rect);
I have tried all kinds of variations with different image types (pgn, PNG, jpg, JPG, tif, TIF....) and nothing works. What am I doing wrong?
QPainter painter(this);
QImage backGround;
painter.setRedirected (this, &backGround, QPoint(0, 0));
painter.setWindow( 0, 0, pixcols - 1, pixrows - 1);
// bunch of painter commands
painter.setRedirected (&backGround, this, QPoint(0, 0));
QString file = "image.png";
if(backGround.save(file, "PGN", -1))
qDebug("it worked");
else
qDebug("it didn't work");
painter.setWindow( 0, 0, pixcols - 1, pixrows - 1);
QRect rect(0, 0, pixcols - 1, pixrows - 1);
painter.drawImage(rect, backGround, rect);
I have tried all kinds of variations with different image types (pgn, PNG, jpg, JPG, tif, TIF....) and nothing works. What am I doing wrong?