将np.array转换为纹理kivy



我有一个代码:

array =  np.array(pyautogui.screenshot())

如何将数组转换为kivy纹理
谢谢你。

您可以将np数组闪电式地放入纹理中,确保纹理的大小和颜色格式与矩阵中的内容相匹配。这里是一个简单的示例。

https://gist.github.com/tshirtman/d14837a06d64b481e1a5dca71c46b1c6

重要的比特是:


# adjust values and size if you want a different color format
world = np.array(
[0. for i in range(SIZE[0] * SIZE[1])],
dtype=np.float32,
)
class Langton(App):
texture = ObjectProperty()
def build(self):
...
# adjust colorfmt if your texture is not greyscale
self.texture = Texture.create(size=SIZE, colorfmt='luminance')
...
return Builder.load_string(KV)
def refresh(self, dt):
self.texture.blit_buffer(world, colorfmt='luminance', bufferfmt='float')
self.root.ids.world.canvas.flag_update()

最新更新