C++ (Qt)#include <QApplication>#include <QGraphicsScene>#include <QGraphicsItem>#include <QImage>#include <QPainter> int main( int argc, char** argv ){ QApplication app( argc, argv ); QGraphicsScene scene1, scene2, scene3; scene1.setSceneRect( -250, -250, 500, 500 ); scene2.setSceneRect( -250, -250, 500, 500 ); scene3.setSceneRect( -250, -250, 500, 500 ); scene1.addRect( QRectF( -200, -200, 400, 400 ), QPen( Qt::black ), QBrush( Qt::green ) ); scene2.addEllipse( -150, -150, 300, 300, QPen( Qt::black ), QBrush( Qt::red ) ); QGraphicsItem* pi = scene3.addRect( QRectF( -50, -50, 100, 100 ), QPen( Qt::black ), QBrush( Qt::blue ) ); pi->setRotation( 45 ); QImage img( 800, 600, QImage::Format_RGB32 ); img.fill( QColor( Qt::white ).rgb() ); QPainter p( &img ); p.setRenderHint( QPainter::Antialiasing ); scene1.render( &p ); scene2.render( &p ); scene3.render( &p ); img.save( "/tmp/test.png" ); return 0;}
scene->render( &p, QRectF (80,0 )); scene2->render( &p , QRectF (80,301));
C++ (Qt)#include <QApplication>#include <QGraphicsScene>#include <QGraphicsItem>#include <QImage>#include <QPainter> int main( int argc, char** argv ){ QApplication app( argc, argv ); QGraphicsScene scene1, scene2, scene3; scene1.addRect( QRectF( -200, -200, 400, 400 ), QPen( Qt::black ), QBrush( Qt::green ) ); scene2.addEllipse( -200, -200, 400, 400, QPen( Qt::black ), QBrush( Qt::red ) ); QGraphicsItem* pi = scene3.addRect( QRectF( -150, -150, 300, 300 ), QPen( Qt::black ), QBrush( Qt::blue ) ); pi->setRotation( 45 ); QImage img( 500, 1400, QImage::Format_RGB32 ); img.fill( QColor( Qt::white ).rgb() ); QPainter p( &img ); p.setRenderHint( QPainter::Antialiasing ); scene1.render( &p, QRectF( 50, 50, 400, 400 ) ); scene2.render( &p, QRectF( 50, 500, 400, 400 ) ); scene3.render( &p, QRectF( 50, 950, 400, 400 ) ); img.save( "/tmp/test.png" ); return 0;}
QImage img(scene->width(), scene2->height()*2.5, QImage::Format_RGB32); img.fill(QColor(Qt::black).rgb()); QPainter p( &img ); scene->render( &p, QRectF (0,img.height()/20,img.width(),img.height()/2)); scene2->render( &p, QRectF (0,img.height()/2,img.width(),img.height()/2)); p.end(); img.save(QString("/Graphic_test/%1.PNG").arg(serial1_1));