我需要调整图像大小,但我想避免使用 PIL,因为我无法使其在 OS X 下工作 - 不要问我为什么......
无论如何,因为我对 gif/pgm/ppm 感到满意,所以 PhotoImage 类对我来说没问题:
photoImg = PhotoImage(file=imgfn)
images.append(photoImg)
text.image_create(INSERT, image=photoImg)
问题是 - 如何调整图像大小?
以下仅适用于 PIL,哪个是非 PIL 等效项?
img = Image.open(imgfn)
img = img.resize((w,h), Image.ANTIALIAS)
photoImg = ImageTk.PhotoImage(img)
images.append(photoImg)
text.image_create(INSERT, image=photoImg)
谢谢你!
因为两者zoom()
and subsample()
想要整数作为参数,我都使用了。
我必须将 320x320 图像大小调整为 250x250,最终得到
imgpath = '/path/to/img.png'
img = PhotoImage(file=imgpath)
img = img.zoom(25) #with 250, I ended up running out of memory
img = img.subsample(32) #mechanically, here it is adjusted to 32 instead of 320
panel = Label(root, image = img)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)