how to fit image to label in Python

穿精又带淫゛_ 提交于 2020-01-03 19:40:16

问题


So in python i have a Label that I'm using to display images. But the images are rather large and they exceed the size of the label. Is there a way to load the images to fit the label without resizing them?

here is what i do now.

labelWidth = top.winfo_screenwidth()
labelHeight = top.winfo_screenheight() 
maxsize = (labelWidth, labelHeight)
im.thumbnail(maxsize, Image.ANTIALIAS)
tkpi = ImageTk.PhotoImage(im)

but this takes way to long.

Thanks in advanced, I'm very new to Python.


回答1:


try:

im = im.resize(maxsize)

instead of:

im.thumbnail(maxsize, Image.ANTIALIAS)


来源:https://stackoverflow.com/questions/26997669/how-to-fit-image-to-label-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!