最佳答案
The following is my first shot which never works:
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()
the error says,
Traceback (most recent call last):
File "try.py", line 10, in <module>
im = Image.open(buffer.read())
File "/awesomepath/python2.7/site-packages/PIL/Image.py", line 1952, in open
fp = __builtin__.open(fp, "rb")
any ideas? I don't want the solution to involve extra packages.