首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Image.texture中刷新CoreImage.texture?

如何从Image.texture中刷新CoreImage.texture?
EN

Stack Overflow用户
提问于 2015-04-08 16:51:19
回答 1查看 404关注 0票数 1

我正在寻找一种方法,以刷新相机的快照微型图像。我有这段代码,但是经过第一次刷新(而不是reloadMiniatures线程中的那个),我什么也没有(黑屏幕)。

我尝试过其他解决方案,但是显示6xMJPEG流太重了(而且我真的不需要高帧率)。在使用AsyncImage和保存图像文件方面取得了一些成功,但这并不是很有效,而且我有这个loading_image需要处理。

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-08 17:33:47

您可以尝试使用Loader来代替:

代码语言:javascript
复制
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.image
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29520715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档