import base64
from PIL import Image
import io
with open("picture.png", "rb") as file:
img = base64.b64encode(file.read())
img = Image.open(io.BytesIO(img))
img.show()
网友
2楼 ·
发布于 2024-05-21 14:02:40
继续eatmeimdanish的想法:您可以手动执行:
import base64
with open('image.gif', 'rb') as imagefile:
base64string = base64.b64encode(imagefile.read()).decode('ascii')
print(base64string) # print base64string to console
# Will look something like:
# iVBORw0KGgoAAAANS ... qQMAAAAASUVORK5CYII=
# or save it to a file
with open('testfile.txt', 'w') as outputfile:
outputfile.write(base64string)
# Then make a simple test program
from tkinter import *
root = Tk()
# Paste the ascii representation into the program
photo = 'iVBORw0KGgoAAAANS ... qQMAAAAASUVORK5CYII='
img = PhotoImage(data=photo)
label = Label(root, image=img).pack()
下面是如何使用PIL打开它。你需要它的字节表示,然后PIL可以打开它的一个类似文件的对象。在
继续eatmeimdanish的想法:您可以手动执行:
这是用tkinter PhotoImage,但我相信你能想出如何使它与PIL一起工作。在
相关问题 更多 >
编程相关推荐