如何在Python中使图像适合标签 [英] how to fit image to label in Python

查看:125
本文介绍了如何在Python中使图像适合标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此在python中,我有一个用于显示图像的标签.但是图像很大,超过了标签的大小.有没有办法在不调整大小的情况下加载图像以适合标签?

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?

这就是我现在要做的.

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

但这要花很长时间.

感谢进阶,我是Python的新手.

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

推荐答案

尝试:

im = im.resize(maxsize)

代替:

im.thumbnail(maxsize, Image.ANTIALIAS)

这篇关于如何在Python中使图像适合标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆