用base64 对图片文件的编码和解码处理
import base64 def convert(image): f = open(image) img_raw_data = f.read() f.close() img_b64_string = base64.b64encode(img_raw_data) convert_img_raw_data = base64.b64decode(img_b64_string) t = open("example.png", "w+") t.write(convert_img_raw_data) t.close() if __name__ == "__main__": convert("test.png")