如何将pylab图保存到内存文件中,并且可以读取到PIL图像中?
- 论坛
- 如何将pylab图保存到内存文件中,并且可以读取到PIL图像中?
17 浏览
如何将pylab图保存到内存文件中,并且可以读取到PIL图像中?
以下是我第一次尝试,但从未成功过:
import cStringIO import pylab from PIL import Image pylab.figure() pylab.plot([1,2]) pylab.title("test") buffer = cStringIO.StringIO() pylab.savefig(buffer, format='png') im = Image.open(buffer.read()) buffer.close()
错误信息如下:
Traceback (most recent call last): File "try.py", line 10, inim = Image.open(buffer.read()) File "/awesomepath/python2.7/site-packages/PIL/Image.py", line 1952, in open fp = __builtin__.open(fp, "rb")
有什么想法吗?我不希望解决方案涉及额外的软件包。