如何为Base64字符串转换为图像? [英] How to convert base64 string to image?

查看:163
本文介绍了如何为Base64字符串转换为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像转换为的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字符串转换为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆