本文介绍了如何从QGraphicsScene / QGraphicsView创建图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定 QGraphicsScene
或 QGraphicsView
,可以创建一个图像文件(最好是PNG或JPG) ?如果是,如何?
Given a QGraphicsScene
, or QGraphicsView
, is it possible to create an image file (preferably PNG or JPG)? If yes, how?
推荐答案
我没有尝试过,但这是如何做的想法。
I have not tried this, but this is the idea of how to do it.
您可以通过多种方式完成此操作
一种形式如下:
You can do this in several waysOne form is as follows:
QGraphicsView* view = new QGraphicsView(scene,this);
QString fileName = "file_name.png";
QPixmap pixMap = QPixmap::grabWidget(view);
pixMap.save(fileName);
//Uses Qpixmap::grabWidget function to create a pixmap and paints the QGraphicsView inside it.
另一个是使用render函数QGraphicsScene :: render():
The other is to use the render function QGraphicsScene::render():
QImage image(fn);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
scene.render(&painter);
image.save("file_name.png")
这篇关于如何从QGraphicsScene / QGraphicsView创建图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!