python String - Image 相互转换
2023-09-14 09:07:03 时间
Image2String
import base64
def image_str():
with open("test.png", "rb") as imageFile:
str = base64.b64encode(imageFile.read())
return str
String2Image
def str_image(str):
fh = open("o_test.png", "wb")
fh.write(str.decode('base64'))
fh.close()
示例
import base64
import sys as sys
def image_str():
with open("test.png", "rb") as imageFile:
str = base64.b64encode(imageFile.read())
return str
def str_image(str):
fh = open("o_test.png", "wb")
fh.write(str.decode('base64'))
fh.close()
str = image_str()
print str
print sys.getsizeof(str)
str_image(str)
相关文章
- [python+nltk] 自然语言处理简单介绍和NLTK坏境配置及入门知识(一)
- Python 线程定时器Timer
- Python 中将 Pandas DataFrame 转换为 JSON?
- Windows下 Python 安装包的配置
- python抽取指定url页面的title方法
- 数据分析:基于Python的自定义文件格式转换系统
- python使用threading获取线程函数返回值的实现方法
- Python实现字符串与数组相互转换功能示例
- python转换emoji字符串
- golang和python的二进制转换
- Python 刷Leetcode题库,顺带学英语单词(41)
- 华为OD机试 - 单词倒序(Java & JS & Python)
- 用Python做一个游戏辅助脚本,完整编程思路分享!
- Qt调用Python详细过程
- 一个有意思还有用的Python包-汉字转换拼音(附零基础学习教程)
- 5本Python书推荐,强化你的程式编程语言观念
- 〖Python零基础入门篇㉘〗- Python中不同数据类型间的转换
- Python爬虫案例:下载文章数据,转制成PDF格式
- 爬虫学习(9):python 自动发送QQ邮箱
- Python学习46:使用@property
- Python将JSON格式数据转换为SQL语句以便导入MySQL数据库
- 【华为机试真题 Python实现】数组的转换
- hashlib库:Python的加密算法实践
- Python爬虫:url中带字典列表参数的编码转换
- python pandas简单使用处理csv文件
- 学习笔记 | Python入门教程
- Ubuntu 安装 Python 3.8
- 排查python内存泄露中几个工具的使用
- 【Leetcode刷题Python】538. 把二叉搜索树转换为累加树
- Python tips:Typing包、enumerate,进制转换等
- Python基于YOLOv5的闯红灯检测系统(完整源码&UI操作界面&部署教程)
- 第25讲:Python字符串的字符转换、字符串劈分、字符串合并
- python 多项式拟合
- Python:4-2月份格式转换程序