gpt4 book ai didi

python - 将(截图捕获的)图像转换为 base 64,而无需在 python 中保存为 png/jpeg

转载 作者:行者123 更新时间:2023-11-28 22:33:03 28 4
gpt4 key购买 nike

我看到很多关于将图像从图像转换为 base 64 字符串的问答,所有这些都涉及将图像物理保存在 pc 上。我想要的是将图像转换为 base 64 字符串,而无需物理保存图像。

如何使用 pyscreenshotImageGrab 实现?

最佳答案

buffer = io.BytesIO()

im=ImageGrab.grab()
im.save(buffer, format='PNG')
im.close()

b64_str = base64.b64encode(buffer.getvalue())

关于python - 将(截图捕获的)图像转换为 base 64,而无需在 python 中保存为 png/jpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40327727/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com