Search code examples
pythonimagepygameresizesurface

Changing size of image in Pygame


I'm creating a Pygame sprite. I need to change its size as the PNG file I've loaded is too big. The dimensions are currently 356x354. I need them to be 35x35

I've loaded the image using this code and declared the variable as img.

img=pygame.image.load("C:\\Pikachu_Sprite.png")

I've then tried to use this code to resize "img"

pygame.transform.scale(img,(35,35))

But it doesn't do anything.

In addition to this I've got an error in the terminal saying libpng warning: Interlace handling should be turned on when using png_read_image.

I don't understand what this is but I suspect it relates to my problem of not being able to resize the image/surface.


Solution

  • You need to assign pygame.transform.scale(img,(35,35)) to a variable otherwise it won't be saved.

    Also, the error message is a bug in an old version of pygame, try updating pygame by using python3 -m pip install -U pygame or if that doesn't work, try python -m pip install Pygame>=2.0.0.dev6.