Loading... 安装PIL包`pip install Pillow` ```python import base64 from PIL import Image from io import BytesIO def base64_to_png(base64_string, output_file): # 解码 Base64 字符串为字节数据 image_data = base64.b64decode(base64_string) # 创建 BytesIO 对象,并将字节数据写入其中 image_bytes = BytesIO(image_data) # 使用 PIL 打开图像 image = Image.open(image_bytes) # 保存图像为 PNG 文件 image.save(output_file, "PNG") # 示例使用 output_file = "output.png" base64_string="iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAACXBIWXMAACE4AAAhOAFFljFgAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAB3TSURBVHgB7d1bchTnFcDxg5BkJ44LQRxSJA8eVmApEqryk4cVACtgtALMCiytALECSytArIDxU6pkEeQFpBhXHqhgbOSH+KIbOWf4xhaj/r6+THdPX/6/KpXwdI8sTXefPt/5Li0CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtNEFAcY8e/Zs4ZdfflmYnZ3tzMzMdE5PTxf05QX99yX7HvP2A93/R/uu+9u/B2/evDmYm5sbLC0tHQgwAQJWi1lgOjk56WpAscD0iX5flLcBqSPFsIC1b9/1//WNfu8fHx8PPv3004EACRCwWuTrr7/u6rfFCxcufGbfpbjAlNYwkGkQ+0q/92/cuNEXIAIBq8H++c9/drRZd1sD1C15G6DimnNV0tcA9li/+qurq/sCCAGrcSyL0ubdZ3qh35a3QaoJBhp0+1oP2yb7ajcCVgNYLUov5nsapLr6n11ptmHwOjw83KD21T4ErBqzbEov3i+kmCA10K8D/fnD5pgGxG/tu2Zvg9CbdL+Ofdf3WfPzY/m9iN+R/A2zLm0ybglagYBVM2eyqc8ln5r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tXrSCRs0vU6Gd3SS+AH+uyLEydTPBIvWENSjOnfb02BteuXRtIg9Q6YI2zAOaK90knXue+hCuQl5SDTxs5gHlcaQNHy2BpbpqJ11ZoJFihqqxnWjyDd8cMb7xt6CBqVMAacYPc+jG7HVjXrQAVZTdgG1ITt59lVm258TYyYBkrokvg7uRqVwMBKiwuy7LWRJuG3jQ2YFkwimkatnW9LtSIy7J8828HdVnRNi+NDVjGLaK3M/66exLtQIAacFnWOVa3kpZpdMAy1jQcu0P19eu+ADVhN1d7uIP8vs6WrUfFuMEmsyEP9iVAjb148aIjAAAAAAAAAAAAAAAAAABk1Kj1sICmsYeA2Hr6b9686cjbEe6PV1dXt6SlhgFrb2/PFrxbl+o9sQZokv2jo6M7Sde71+vytn57NP66Bq/7N27c2EzyM9xTue3Bt12pCJvLe3h4uJFl3f8Z96HYH0+wAoq1qMHjiS0znXD/B1Ev2iqkSX+G/f+kYo8T04Dbc0E0NZv8fFsAlKXj1sQPsqag+J9PsKCZWux1u7u7uyjVfWhrN0Xg/k3jV2sAqkYzjINJ99G6VuzP0MDYuIeCzOgHsyUAyjLQ+lM/bidtMg0ksNKoZlj7EsPViPpSQVbHyvKUpRn34dljrmI/AACZ2cXZt4fMJtnZLmbfirn2etKCtf7/1rRncVuSPcyiDAcWrDRDzLQmHcMagAqzOpRe3FZ87+jXcNnvJBlaU/0fWTHRRucPYCUAAAAASUVORK5CYII=" base64_to_png(base64_string, output_file) ``` ![image.png](http://type.zimopy.com/usr/uploads/2023/06/3707357741.png) 最后修改:2023 年 06 月 07 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏