纵有疾风起
人生不言弃

python String – Image 相互转换

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 相互转换
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录