How to render a part of QGraphicsScene and save It as image file PyQt5

后端 未结 1 1078
伪装坚强ぢ
伪装坚强ぢ 2021-01-17 01:04

Suppose I have QGraphicsPixmapItem from loaded image which is added to QGraphicsScene. And suppose I\'ll add several QGraphicsPolygonItem

相关标签:
1条回答
  • 2021-01-17 01:18

    Untested, but using QGraphicsScene::render you should be able to do something like...

    def _save_image(self):
    
        # Get region of scene to capture from somewhere.
        area = get_QRect_to_capture_from_somewhere()
    
        # Create a QImage to render to and fix up a QPainter for it.
        image = QImage(area.size(), QImage.Format_ARGB32_Premultiplied)
        painter = QPainter(image)
    
        # Render the region of interest to the QImage.
        self.scene.render(painter, image.rect(), area)
        painter.end()
    
        # Save the image to a file.
        image.save("capture.png")
    
    0 讨论(0)
提交回复
热议问题