How to get the picture size in pygame (python)

℡╲_俬逩灬. 提交于 2019-12-23 03:28:06

问题


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


回答1:


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.




回答2:


import pygame
foo = pygame.image.load(PATH).get_rect().size
print(foo)

Return the size in a tupple



来源:https://stackoverflow.com/questions/16840711/how-to-get-the-picture-size-in-pygame-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!