问题
I'm trying to rescale an image on pygame but it instead crops the image, I'm just looking to change the pixel width and height of the image.
I used pygame.transform.scale
and used 1900, 600 as the parameters, the original image is a 1920x1080
mainmenu = pygame.image.load("Main_Menu.png")
mainmenu = pygame.transform.scale(mainmenu, (1900,600))
screen.blit(background, (0, 0))
I expected the image to be rescaled to a 1900x600 image but it instead output a badly cropped image in the 1900x600 format.
回答1:
You've to use pygame.transform.smoothscale() rather than pygame.transform.scale().
Use convert() or convert_alpha() to convert the surface to a surface with a with proper pixel format
mainmenu = pygame.image.load("Main_Menu.png")
mainmenu = pygame.transform.smoothscale(mainmenu.convert_alpha(), (1900,600))
screen.blit(background, (0, 0))
While scale()
does a scaling operation, which is as fast as possible, smoothscale()
scales smoothly and calculates area averages of the colors which cover the pixels.
来源:https://stackoverflow.com/questions/55319967/how-do-i-properly-rescale-an-image-on-pygame-without-it-being-badly-cropped