![](/img/trans.png)
[英]How to convert Matplotlib figure to PIL Image object (without saving image)
[英]how to convert a PIL image to string and then convert it back to PIL image? The convsersion is to be done without saving it to a new file
我目前正在為字節字符串轉換執行此操作,但我需要轉換為字符串。
img=Image.fromarray(img)
output = io.BytesIO()
img.save(output, format="png")
image_as_string = output.getvalue()
img=Image.open(io.BytesIO(image_as_string))
img.save('strimg.png')
這是我使用 base64 的解決方案。
import base64
img = Image.open("test.png")
output = io.BytesIO()
img.save(output, format="png")
image_as_string = base64.b64encode(output.getvalue())
#encrypting/decrypting
img=Image.open(io.BytesIO(base64.b64decode(image_as_string)))
img.save('string.png')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.