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()
示例

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
还没有人抢沙发呢~