簡體   English   中英

Kivy以清晰的背景拍攝截圖

[英]Kivy take screenshot with clear background

我正在開發一個Kivy應用程序,讓用戶可以在模板上定位圖像和文本標簽。 完成后,將裁剪生成的圖像以適合模板。

我需要清除圖像中的所有空白區域,因為我將打印圖像並且不想浪費墨水。 然而,Kivy用黑色填充所有空白區域。 有沒有辦法讓Kivy的export_to_png()函數使用透明背景而不是黑色背景?

我可能錯了,但看起來透明的顏色是硬編碼的。

看一下源代碼 ,似乎ClearColor被硬編碼為黑色。

def export_to_png(self, filename, *args):
        '''Saves an image of the widget and its children in png format at the
        specified filename. Works by removing the widget canvas from its
        parent, rendering to an :class:`~kivy.graphics.fbo.Fbo`, and calling
        :meth:`~kivy.graphics.texture.Texture.save`.

        .. note::

            The image includes only this widget and its children. If you want
            to include widgets elsewhere in the tree, you must call
            :meth:`~Widget.export_to_png` from their common parent, or use
            :meth:`~kivy.core.window.WindowBase.screenshot` to capture the whole
            window.

        .. note::

            The image will be saved in png format, you should include the
            extension in your filename.

        .. versionadded:: 1.9.0
        '''

        if self.parent is not None:
            canvas_parent_index = self.parent.canvas.indexof(self.canvas)
            self.parent.canvas.remove(self.canvas)

        fbo = Fbo(size=self.size, with_stencilbuffer=True)

        with fbo:
            ClearColor(0, 0, 0, 1)
            ClearBuffers()
            Scale(1, -1, 1)
            Translate(-self.x, -self.y - self.height, 0)

我想你可以嘗試更新Widget模塊代碼以接受一個參數來設置ClearColor

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM