本文介紹了在 Kivy 中從內(nèi)存中加載圖像的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在內(nèi)存中有一張圖片格式(從pyplot輸出),我想通過Kivy直接在Android上顯示它,但我不想創(chuàng)建圖片文件.有沒有辦法做到這一點(diǎn)?在 pyplot 上,我可以通過將對象寫入對象來生成類似對象的文件,但我不知道如何將其放入 Kivy.
I have a picture in memory a format (output from pyplot) and I want to directly show it on the Android through Kivy, but I don't want to create a picture file. Is there any way to do this? On pyplot I am able to generate the file like object by writing it the object, but I don't know how to put it into Kivy.
推薦答案
您可以使用 StringIO 將文件保存到緩沖區(qū)中(參見:Python中的二進(jìn)制緩沖區(qū)).
You could save the file into a buffer with StringIO (see this: Binary buffer in Python).
類似:
from StringIO import StringIO
buff = StringIO()
plt.savefig(buff)
buff.seek(0)
from kivy.core.image.img_pygame import ImageLoaderPygame
imgdata = ImageLoaderPygame(buff)._data
這篇關(guān)于在 Kivy 中從內(nèi)存中加載圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!