Python base64字符串到PyPng而不保存文件 [英] Python base64 string to PyPng without saving file
本文介绍了Python base64字符串到PyPng而不保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不保存到磁盘然后打开'out.png'的情况下执行此操作?
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()
推荐答案
使用 bytes
关键字
r = png.Reader(bytes=decoded)
这篇关于Python base64字符串到PyPng而不保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文