How to get the picture size in pygame (python)

2019-06-02 10:44发布

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 ?

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

2条回答
我只想做你的唯一
2楼-- · 2019-06-02 10:48
import pygame
foo = pygame.image.load(PATH).get_rect().size
print(foo)

Return the size in a tupple

查看更多
迷人小祖宗
3楼-- · 2019-06-02 11:02

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).

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

查看更多
登录 后发表回答