我正在将图像转换为 base64 字符串并将其从 android 设备发送到服务器.现在,我需要将该字符串改回图像并将其保存在数据库中.
I'm converting an image to base64 string and sending it from android device to the server. Now, I need to change that string back to an image and save it in the database.
有什么帮助吗?
试试这个:
import base64
imgdata = base64.b64decode(imgstring)
filename = 'some_image.jpg' # I assume you have a way of picking unique filenames
with open(filename, 'wb') as f:
f.write(imgdata)
# f gets closed when you exit the with statement
# Now save the value of filename to your database
这篇关于如何将base64字符串转换为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!