我正在尝试使用以下简单代码使用python编码和解码相同的图像文件。但是每次输出文件都大于输入文件,并且无法打开。这段代码有什么问题?
import base64
with open("img.jpeg", "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
decoded_string = base64.b64decode(encoded_string)
with open("test_img.jpeg", "w") as image_file2:
image_file2.write(decoded_string);
原始文件:https : //filebin.ca/3j6aIDlWEYdV/img.jpeg
结果文件:https : //filebin.ca/3j6arBo85Lcg/test_img.jpeg
尝试将写入模式更改为"wb"
。您现在的写作和阅读都采用了不同的格式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句