python 将图片与字符串相互转换
生活随笔
收集整理的這篇文章主要介紹了
python 将图片与字符串相互转换
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
import base64
image='1.jpg'#將圖片encode為二進(jìn)制字符串方法一
with open(image,'rb') as f:str=base64.b64encode(f.read())
print(type(str))#將圖片encode為二進(jìn)制字符串方法二
f=open(image,'rb')
f_str=base64.b64encode(f.read())
f.close()
print(type(f_str))#將二進(jìn)制字符串(圖片)decode為圖片
str=f_str
file_str=open('2.jpg','wb')
file_str.write(base64.b64decode(str))
file_str.close()
?
總結(jié)
以上是生活随笔為你收集整理的python 将图片与字符串相互转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python Pytest中fixtur
- 下一篇: html中svg的css,HTML5 内