<small id='j32kV'></small><noframes id='j32kV'>

    <i id='j32kV'><tr id='j32kV'><dt id='j32kV'><q id='j32kV'><span id='j32kV'><b id='j32kV'><form id='j32kV'><ins id='j32kV'></ins><ul id='j32kV'></ul><sub id='j32kV'></sub></form><legend id='j32kV'></legend><bdo id='j32kV'><pre id='j32kV'><center id='j32kV'></center></pre></bdo></b><th id='j32kV'></th></span></q></dt></tr></i><div id='j32kV'><tfoot id='j32kV'></tfoot><dl id='j32kV'><fieldset id='j32kV'></fieldset></dl></div>
    • <bdo id='j32kV'></bdo><ul id='j32kV'></ul>
    <legend id='j32kV'><style id='j32kV'><dir id='j32kV'><q id='j32kV'></q></dir></style></legend>
  • <tfoot id='j32kV'></tfoot>

      1. 如何渲染 QGraphicsScene 的一部分并将其保存为图像

        时间:2023-08-05
        • <bdo id='fLm8f'></bdo><ul id='fLm8f'></ul>
        • <i id='fLm8f'><tr id='fLm8f'><dt id='fLm8f'><q id='fLm8f'><span id='fLm8f'><b id='fLm8f'><form id='fLm8f'><ins id='fLm8f'></ins><ul id='fLm8f'></ul><sub id='fLm8f'></sub></form><legend id='fLm8f'></legend><bdo id='fLm8f'><pre id='fLm8f'><center id='fLm8f'></center></pre></bdo></b><th id='fLm8f'></th></span></q></dt></tr></i><div id='fLm8f'><tfoot id='fLm8f'></tfoot><dl id='fLm8f'><fieldset id='fLm8f'></fieldset></dl></div>

          <small id='fLm8f'></small><noframes id='fLm8f'>

        • <legend id='fLm8f'><style id='fLm8f'><dir id='fLm8f'><q id='fLm8f'></q></dir></style></legend>

            <tfoot id='fLm8f'></tfoot>
              <tbody id='fLm8f'></tbody>
                  本文介绍了如何渲染 QGraphicsScene 的一部分并将其保存为图像文件 PyQt5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  假设我有来自加载图像的 QGraphicsPixmapItem,它被添加到 QGraphicsScene.假设我将在场景中添加几个 QGraphicsPolygonItem.如何将场景的一部分渲染为全尺寸图像,同时使用不在空白区域中的多边形保存该区域作为图像文件.

                  Suppose I have QGraphicsPixmapItem from loaded image which is added to QGraphicsScene. And suppose I'll add several QGraphicsPolygonItem's on scene. How I can render a part of the scene as full-size image both with polygons that are not in blank area and save this area as image file.

                  class ImageView(QtWidgets.QGraphicsView):
                  
                      def __init__(self, parent):
                          super(ImageView, self).__init__(parent)
                          self.setFocus()
                          self._zoom = 0
                          self._empty = True
                          self.scene = QtWidgets.QGraphicsScene(self)
                          self._image = QGraphicsPixmapItem()
                          self.scene.addItem(self._image)
                          self.setScene(self.scene)
                  
                          # some other actions
                          foo()
                  
                      def fitInView(self):
                          # custom fit in view and scaling
                          bar()
                  
                  
                      # some other methods
                  
                  class MainWindow(QtWidgets.QWidget):
                      def __init__(self):
                          self.viewer = ImageView(self)
                          foo()
                  
                      def _save_image(self):
                          # method that I need to implement
                          pass
                  

                  推荐答案

                  未经测试,但使用 QGraphicsScene::render 你应该可以做类似...

                  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")
                  

                  这篇关于如何渲染 QGraphicsScene 的一部分并将其保存为图像文件 PyQt5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  <tfoot id='b5ryj'></tfoot>
                    <bdo id='b5ryj'></bdo><ul id='b5ryj'></ul>
                      <tbody id='b5ryj'></tbody>
                  • <i id='b5ryj'><tr id='b5ryj'><dt id='b5ryj'><q id='b5ryj'><span id='b5ryj'><b id='b5ryj'><form id='b5ryj'><ins id='b5ryj'></ins><ul id='b5ryj'></ul><sub id='b5ryj'></sub></form><legend id='b5ryj'></legend><bdo id='b5ryj'><pre id='b5ryj'><center id='b5ryj'></center></pre></bdo></b><th id='b5ryj'></th></span></q></dt></tr></i><div id='b5ryj'><tfoot id='b5ryj'></tfoot><dl id='b5ryj'><fieldset id='b5ryj'></fieldset></dl></div>

                          <legend id='b5ryj'><style id='b5ryj'><dir id='b5ryj'><q id='b5ryj'></q></dir></style></legend>

                          <small id='b5ryj'></small><noframes id='b5ryj'>