gpt4 book ai didi

python - Kivy 截图,背景清晰

转载 作者:行者123 更新时间:2023-11-30 23:04:31 24 4
gpt4 key购买 nike

我正在开发一个 Kivy 应用程序,它允许用户在模板上放置图像和文本标签。完成后,生成的图像将被裁剪以适合模板。

我需要图像中的所有空白区域都清晰,因为我将打印图像并且不想浪费墨水。然而,Kivy 用黑色填充了所有空白。 Kivy的export_to_png()函数有没有办法使用透明背景而不是黑色背景?

最佳答案

我可能是错的,但看起来透明颜色是硬编码的。

查看source code看来 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

关于python - Kivy 截图,背景清晰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33677925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com