- Game Programming using Qt 5 Beginner's Guide
- Pavel Strakhov Witold Wysota Lorenz Haas
- 59字
- 2021-08-27 18:31:06
Saving a scene to an image file
We've only displayed our scene in the view so far, but it is also possible to render it to an image, a printer, or any other object Qt can use for painting. Let's save our scene to a PNG file:
QRect rect = scene.sceneRect().toAlignedRect(); QImage image(rect.size(), QImage::Format_ARGB32); image.fill(Qt::transparent); QPainter painter(&image); scene.render(&painter); image.save("scene.png");