python String - Image 相互转换
2023-09-27 14:25:20 时间
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中,如何将字符串转换为数字(将数字转换为整型),字符串的10转换为整型的10,10.5转换为10
- 将numpy和python类型数据的相互转换
- 编程零基础应当如何开始学习 Python?
- python注释#、Ctrl+/
- 每天一个python小知识——如何在Python 3中转换数据类型
- python的包管理
- 【Python】+字符串转换为日期(互转)+获取当前时间+获取当前时间戳
- Python小任务 - 如何编写指定时间执行的Python小程序
- Python 进制转换 二进制 八进制 十进制 十六进制
- 《Python密码学编程》——2.4 特色程序
- 《Python核心编程(第3版)》——2.7 相关模块
- Python自动化运维工具fabric的安装
- 《Python编程实战:运用设计模式、并发和程序库创建高质量程序》—— 导读
- Python数据处理Tips数据预处理操作方法汇总
- python编程之处理GB级的大型文件
- python pdf 文件,流转换
- Python数学函数
- Python无限循环
- 【项目实战】——Python打包正装换底色代码为exe文件(可在其他无Python环境下运行)
- 一些简单基础的Python编程
- Python:类和对象的详细分析
- 使用python将MNIST数据转换为图片