我正在寻找一种方法,以刷新相机的快照微型图像。我有这段代码,但是经过第一次刷新(而不是reloadMiniatures线程中的那个),我什么也没有(黑屏幕)。
我尝试过其他解决方案,但是显示6xMJPEG流太重了(而且我真的不需要高帧率)。在使用AsyncImage和保存图像文件方面取得了一些成功,但这并不是很有效,而且我有这个loading_image需要处理。
from kivy.app import App
from kivy.uix.image import Image
import time
import threading
import urllib
from kivy.core.image import Image as CoreImage
from io import BytesIO
class TestApp(App):
def reloadMiniatures(self):
while True:
data = BytesIO(urllib.urlopen("http://10.0.13.206:9000/?action=snapshot").read())
time.sleep(3)
self.image.texture = CoreImage(data, ext='jpg').texture
def build(self):
data = BytesIO(urllib.urlopen("http://10.0.13.206:9000/?action=snapshot").read())
self.image = Image()
self.image.texture = CoreImage(data, ext='jpg').texture
miniatures = threading.Thread(target=self.reloadMiniatures)
miniatures.daemon = True
miniatures.start()
return self.image
TestApp().run()发布于 2015-04-08 17:33:47
您可以尝试使用Loader来代替:
def load_miniatures(self, *args):
proxy = Loader.image('http://10.0.13.206:9000/?action=snapshot')
proxy.bind(on_load=self.receive_miniatures)
def receive_miniatures(self, proxy):
if proxy.image.texture:
self.image.texture = proxy.image.texture
Clock.schedule_once(self.load_miniatures, 0.1)
def build(self):
self.image = Image()
self.load_miniatures()
return self.imagehttps://stackoverflow.com/questions/29520715
复制相似问题