如何解决将np.array转换为纹理基维
我有一个代码:
array = np.array(pyautogui.screenshot())
如何将数组转换为基维纹理?
谢谢你。
解决方法
这是一个简单的示例,您可以将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()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。