How do i properly rescale an image on PyGame without it being badly cropped?

ぃ、小莉子 提交于 2021-02-13 17:31:11

问题


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

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