0
如何從QGraphicsScene
渲染圖形圖像PyQt的如何保存從QGraphicsScene圖形圖像PyQt的
我有QGraphicsScene
的圖像,它是由多個QGraphicsPixMapItem
項目創建。
我需要將其作爲磁盤上的單個映像呈現出來。
感謝
如何從QGraphicsScene
渲染圖形圖像PyQt的如何保存從QGraphicsScene圖形圖像PyQt的
我有QGraphicsScene
的圖像,它是由多個QGraphicsPixMapItem
項目創建。
我需要將其作爲磁盤上的單個映像呈現出來。
感謝
你只得到你想要捕捉的,那麼你結合的邊界矩形使其到QPixmap
。您可以在此時保存QPixmap
。
未經檢驗的,而應該是沿着線...
import operator
items = get_target_items() # just get all the items you want
# combine all the scene rects for the items
# equiv: totalRect = rect1 | rect2 | ...
totalRect = reduce(operator.or_, (i.sceneBoundingRect() for i in items))
pix = QtGui.QPixmap(totalRect.width(), totalRect.height())
painter = QtGui.QPainter(pix)
scene.render(painter, totalRect)
pix.save("capture.jpg", "JPG")