c++ - 给定一个 QGraphicSscene 和一个 QGraphicsView 我怎样才能写一个 jpg 文件?

标签 c++ qt

给定一个 QGraphicSscene 和一个 QGraphicsView,我如何从中编写一个 jpg 文件?

qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(-300, -300, 600, 600);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);

qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

myPlot *myplot = new myPlot;
scene->addItem(myplot);

QGraphicsView *view = new QGraphicsView();
view->setScene(scene);
view->setRenderHint(QPainter::Antialiasing);
view->setBackgroundBrush(Qt::yellow);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
view->resize(1000, 800);
view->show();

最佳答案

QImage img(yourScene->sceneRect().width(), yourScene->sceneRect().height(), QImage::Format_ARGB32);
QPainter painter(&img);
yourScene->render(&painter, yourScene->sceneRect());
img.save("scene.jpg");

关于c++ - 给定一个 QGraphicSscene 和一个 QGraphicsView 我怎样才能写一个 jpg 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17816997/

相关文章:

c++ - vector 中的指针

c++ - 如何有效地使用 C++11 随机生成器?

qt - 使用哪个 Qt 小部件来实现图像缩略图浏览器(显示图 block )?

android - 真正的开源跨平台移动开发工具包

c++ - gflags 链接器错误 : undefined reference

c++ - delete[] 字符数组

c++ - 大量关键部分有任何问题吗?

c++ - 如何使用诺基亚 sdk 获取显示宽度和高度?

Linux QT OpenCL 基本设置

qt - 在 Qt 项目中引用库的最简单方法是什么?