时间: 2020-09-3|31次围观|0 条评论


Image2String

import base64def 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()

示例

python String – Image 相互转换插图

import base64import sys as sysdef image_str():    with open("test.png", "rb") as imageFile:        str = base64.b64encode(imageFile.read())        return strdef str_image(str):    fh = open("o_test.png", "wb")    fh.write(str.decode('base64'))    fh.close()str = image_str()print strprint sys.getsizeof(str)str_image(str)

View Code

 

文章转载于:https://www.cnblogs.com/kaituorensheng/p/12618064.html

原著是一个有趣的人,若有侵权,请通知删除

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《python String – Image 相互转换
   

还没有人抢沙发呢~