我正在编写一个具有XY绘图的应用程序。我有一个例程,每秒记录数十次(使用Points
指令)数百个点。定期地,我想使用Kivy Fbo将点绘制到纹理中,因此我的画布不会处理兆字节的顶点指令。绘制点后,我想将纹理重新加载到画布上。画布还在处理其他图形指令,所以我不能只清除它或类似的东西。
尽管我确信我的方法有问题,但我将在下面提供我要尝试做的代码片段。当前,对Fbo纹理上的save()
的调用会引发以下异常:
AttributeError:'_io.BytesIO'对象没有属性'encode'
Kivy版本:1.10.1,Python 3.5.4(64位Windows 7):
def _save_persist(self):
#imports:
#from PIL import Image
#from kivy.core.image import Image as CoreImage
#from kivy.uix.image import Image as kiImage
#from io import BytesIO
self.persist_fbo = Fbo(size=(self.width,self.height))
#chan_info is a list containing data about each channel
#_persist_chan_inst is a dictionary of InstructionGroup objects
for chan in self.chan_info:
persist_inst = self._persist_chan_inst.get(chan.chan_name)
if not persist_inst is None:
self.persist_fbo.add(persist_inst)
self.persist_fbo.draw()
bytebuff = BytesIO()
pimg = Image.new("RGBA",(int(self.width),int(self.height)),(0,0,0,0))
pimg.save(bytebuff,format="PNG")
bytebuff.seek(0)
self.persist_fbo.texture.save(bytebuff)
img = CoreImage(arg=bytebuff,ext='PNG')
self.texture = img