问题
How do you do this without saving to disk and then opening 'out.png' ?
r = requests.get(url)
mine,encoded = r.json()[0]['data'].split(',') #if it is segmentation
decoded = base64.decodestring(encoded)
if mine == 'data:image/png;base64':
#TODO do this from memory
g = open("out.png", "w")
g.write(decoded)
g.close()
r = png.Reader('out.png')
print r.read()
回答1:
Use the bytes keyword
r = png.Reader(bytes=decoded)
回答2:
base53.decodestring() returns a string of the binary data, and according to this page png.Reader() can take a string as input, so you just have to link the two together.
来源:https://stackoverflow.com/questions/27218529/python-base64-string-to-pypng-without-saving-file