如何使用 Kivy 的 Core Image?

How To Use Kivy's Core Image?

我有一个网格布局,正在向其中添加一些我想用于显示图片的 CoreImage 小部件。我选择不使用 uix.image,因为 CoreImage 速度更快,而且我想经常在几张图片之间切换。

当我执行 self.add_widget(CoreImage('Transparent.png')) 时,我的程序会崩溃。

Traceback (most recent call last):
   File "/path/to/my/app.py", line 1030, in <module>
     MyApp().run()
   File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 798, in run
     root = self.build()
   File "/path/to/my/app.py", line 702, in build
     self.build_grid()
   File "/path/to/my/app.py", line 696, in build_grid
     self.grid.build_self()
   File "/path/to/my/app.py", line 134, in build_self
     self.add_widget(CoreImage('Transparent.png'))
   File "/usr/lib/python2.7/dist-packages/kivy/uix/layout.py", line 80, in add_widget
     size_hint=self._trigger_layout)
   File "_event.pyx", line 436, in kivy._event.EventDispatcher.bind (kivy/_event.c:5429)
 KeyError: 'size_hint'

我做错了什么?当我使用 uix.image.

时这很好用

kivy.core.image.Image(我假设这就是你的意思)不是一​​个小部件,你不能这样使用它。使用 kivy.uix.image.Image.

我尝试对显示一堆内存加载图像做同样的事情。结果是这样的:

from kivy.uix.image import Image
from kivy.core.image import Image as CoreImage

self.add_widget(Image(texture=CoreImage('Transparent.png').texture))

希望对您有所帮助。