如何在 PyGame 上正确重新缩放图像而不会被严重裁剪? [英] How do i properly rescale an image on PyGame without it being badly cropped?

查看:166
本文介绍了如何在 PyGame 上正确重新缩放图像而不会被严重裁剪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 pygame 上重新缩放图像,但它会裁剪图像,我只是想更改图像的像素宽度和高度.

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.

我用了pygame.transform.scale,参数是1900、600,原图是1920x1080

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

我希望将图像重新缩放为 1900x600 的图像,但结果却以 1900x600 格式输出了裁剪严重的图像.

I expected the image to be rescaled to a 1900x600 image but it instead output a badly cropped image in the 1900x600 format.

推荐答案

你必须使用 pygame.transform.smoothscale() 而不是 pygame.transform.scale().
使用 convert()convert_alpha() 将表面转换为具有适当像素格式的表面

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

虽然 scale() 执行缩放操作,它尽可能快,smoothscale() 平滑缩放并计算覆盖像素的颜色的面积平均值.

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.

这篇关于如何在 PyGame 上正确重新缩放图像而不会被严重裁剪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆