Python Kivy拍摄背景清晰的屏幕截图
我正在开发一个Kivy应用程序,它可以让用户在模板上定位图像和文本标签。完成后,生成的图像将被裁剪以适合模板Python Kivy拍摄背景清晰的屏幕截图,python,png,transparency,kivy,alpha,Python,Png,Transparency,Kivy,Alpha,我正在开发一个Kivy应用程序,它可以让用户在模板上定位图像和文本标签。完成后,生成的图像将被裁剪以适合模板 我需要在图像中的所有空白是清晰的,因为我将打印图像,不想浪费墨水。然而,Kivy用黑色填充了所有的空白。Kivy的export_to_png()函数有没有办法使用透明背景而不是黑色背景?我可能错了,但看起来透明颜色是硬编码的 看一下屏幕,似乎ClearColor硬编码为黑色 def export_to_png(self, filename, *args): '''Save
我需要在图像中的所有空白是清晰的,因为我将打印图像,不想浪费墨水。然而,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)
我想您可以尝试更新小部件模块代码,以接受一个参数来设置
ClearColor
我修改了函数,将Window.ClearColor用于ClearColor。这将在嵌入式应用程序中使用,所以我不太担心跨平台兼容性。是的,很有魅力。将透明颜色alpha设置为0,黑色背景消失!