in BGE, I am trying to generate some images with matplotlib, then want to put these images as an object texture.
My first try was ok, I
- generate the image (plplot)
- save it to disk (PIL savefig)
- load the image and put it as texture (Texture imageFFmpeg)
Code:
# plot data
plt.plot(x,y)
plt.savefig('plot.png')
# put image on object as texture
matID=bge.texture.materialID(here.objects['graph1'],"MAplot1mat")
bge.logic.gp1=bge.texture.Texture(here.objects['graph1'],matID)
url_ima=bge.logic.expandPath('//plot.png')
bge.logic.gp1.source=bge.logic.ImageFFmpeg(url_ima)
bge.logic.gp1.refresh(True)
I would like to avoid saving image on disk. So I tried to use an Image Buffer to let the matplotlib image (in memory) to be saved as an image buffer, to feed into the bge.texture. No way.
Code:
bge.logic.plot=bge.texture.Texture(scene.objects['floor'],0)
image_buffer=bge.texture.imageToArray(floor_figure)
bge.logic.floorplot.source=bge.texture.ImageBuff()
bge.logic.floorplot.source.load(image_buffer,20,20)
Question: is there a way to let an image from matplotlib (in memory, not saved onto disk) to fit into a texure?
Thank you, please ask for more info if my explanation is not clear enough.
Roberto
image.pixels
may give more examples. $\endgroup$