gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:43:02 24 4
gpt4 key购买 nike

给定一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com