简体   繁体   English

PySimpleGUI:如何获取图像的大小

[英]PySimpleGUI: How to get size of an image

I have an image viewer that shows the selected image.我有一个显示所选图像的图像查看器。 However I have different sizes of images and I would like to access the selected image size in order to have a fixed GUI.但是我有不同大小的图像,我想访问选定的图像大小以获得固定的 GUI。 Otherwise GUI resizes and images are not showing properly.否则 GUI 调整大小和图像无法正确显示。 Is there any way to see the size of an image?有没有办法查看图像的大小? After I get the image size I am thinking of subsampling according to its size.在获得图像大小后,我正在考虑根据其大小进行二次采样。 Thanks.谢谢。

from PIL import Image

with Image.open('test.png') as im:
    size = im.size
    print(size)

Here is a way using PIL Image package.这是一种使用 PIL Image package 的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM