Image export looks messed up
I'm trying to export the contents of my QGraphicsScene to PNG. For some reason I have to maintain the scene's bounding rectangle myself.
Here's a sample export that should contain a purple ellipse and an orange rectangle on a transparent background:
http://i.imgur.com/WHOYL.png
Why is the exported image messed up like that? Are there any common symptoms that I should look for in my code?
Re: Image export looks messed up
How exactly do you export the scene to the image?
Re: Image export looks messed up
Code:
QString filename
= QFileDialog::getSaveFileName(this,
"Export image",
"",
"Images (*.png)");
int imgWidth = this->myGraphicsScene->width();
int imgHeight = this->myGraphicsScene->height();
qpainter.begin(&qimg);
this->myGraphicsScene->render(&qpainter);
qpainter.end();
qimg.save(filename);
Re: Image export looks messed up
You have to fill your image with transparency first. Otherwise you'll have it initialized with whatever happens to be in the chunk of memory assigned as buffer to your image.
Code:
qimg.fill(Qt::transparent);
Re: Image export looks messed up
Yeeha, that works! Thanks!