我正在寻找一种方法来为WS_STYLECHANGED
小部件的source
指定 numpy图像阵列,而又不另存为“ .png”或“ .jpg”之类的文件。
我知道一种使用canvas(Image
,Texture.create()
,blit_buffer()
)的方法.....还有其他方法吗?
Rectangle()
答案 0 :(得分:1)
您必须使图像通过Texture:
import kivy
from kivy.app import App
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.graphics.texture import Texture
import cv2
class Test(Widget):
def __init__(self, **kwargs):
super(Test, self).__init__(**kwargs)
img = cv2.imread('0.png', cv2.IMREAD_UNCHANGED)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.flip(img, 0)
w, h, _ = img.shape
texture = Texture.create(size=(w, h))
texture.blit_buffer(img.flatten(), colorfmt='rgb', bufferfmt='ubyte')
w_img = Image(size=(w, h), texture=texture)
self.add_widget(w_img)
class DemoApp(App):
def build(self):
return Test()
if __name__ == '__main__':
DemoApp().run()