[英]How can you maintain the aspect ratio when using the Python Image Library and ImageTk.PhotoImage(Image.open(“somefile.py”))
我已經在互聯網上進行了搜索,但是所有結果都包括您使用Image.open("somefile.py")
的答案,但是,我無法找到如何在使用ImageTk.PhotoImage(Image.open("somefile.py"))
時保持縱橫比和縮小圖像ImageTk.PhotoImage(Image.open("somefile.py"))
連同 GUI 庫 Tkinter。
你想要thumbnail()方法:
from PIL import Image
# Open the image
im = Image.open('SomeFile.png')
# Create reduced version whilst maintaining aspect ratio
im.thumbnail((newWidth,newHeight))
# Make ImageTk.PhotoImage from resized image
tkPI = ImageTk.PhotoImage(im)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.