import base64
# 将图像文件编码为 Base64
with open("image.png", "rb") as image_file:
encoded_image = base64.b64encode(image_file.read())
with open("encoded_image.txt", "wb") as encoded_file:
encoded_file.write(encoded_image)
# 将 Base64 编码的字符串解码为图像文件
with open("encoded_image.txt", "rb") as encoded_file:
encoded_image = encoded_file.read()
image_data = base64.b64decode(encoded_image)
with open("decoded_image.png", "wb") as image_file:
image_file.write(image_data)
网友评论