【Python】将图片转为base64数据流
图片转base64
def IconToBase64(self, UIPhoto):
with open(UIPhoto, 'rb') as image_file:
base64_string = base64.b64encode(image_file.read()).decode('utf-8')
# 如果要得到Data URL,可以加上前缀
data_url = f"data:image/jpeg;base64,{base64_string}"
r = data_url.split(",")
b = r[1]
print(r)
print(b)
return b
运行
if __name__ == '__main__':
a = r"D:\icon\列A\1.jpeg"
demo = IconColor().IconToBase64(a)
执行结果
打印r
打印b
-------------------------------------------------------------------------------------
如果万事开头难 那请结局一定圆满 @ Phoenixy
-------------------------------------------------------------------------------------

浙公网安备 33010602011771号