如何在pygame(python)中获取图片大小 [英] How to get the picture size in pygame (python)

查看:5809
本文介绍了如何在pygame(python)中获取图片大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我正在使用图片,并且我想知道文件中图片的大小

If I'm using an image and I want to know the image's size in the file.

有一个功能可以获取图片的高度和宽度?

There is a function to get the picture's height and width ?

编辑:我当然用pygame.image.load(PATH)将图像加载到程序中。

Of course I loaded the image to the program with pygame.image.load(PATH).

推荐答案

我相信您需要先将图像加载为Surface,然后才能获得其宽度和高度。你可以用 foo = pygame.image.load(PATHNAME)

I believe you need to load the image as a Surface before you can get its width and height. You do that with foo = pygame.image.load(PATHNAME).

然后你可以得到宽度和使用foo.get_rect()创建一个Rectangle并询问矩形。

Then you can get the width and height by creating a Rectangle with foo.get_rect() and asking the rectangle.

这篇关于如何在pygame(python)中获取图片大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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