4

我想旋转图像并保持边缘平滑。

这是它的样子

原始图像

并且旋转后

旋转图像

我正在使用的代码看起来像

def rot_center(self, image, angle):
   """rotate an image while keeping its center and size"""
   orig_rect = image.get_rect()
   rot_image = pygame.transform.rotate(image, angle)
   rot_rect = orig_rect.copy()
   rot_rect.center = rot_image.get_rect().center
   rot_image = rot_image.subsurface(rot_rect).copy()
   return rot_image

有什么我做错了吗?

4

3 回答 3

6

尝试使用pygame.transform.rotozoom的比例1.它说它已过滤,我认为这意味着 AA。

于 2012-11-07T21:23:40.847 回答
1

rotozoom 的问题是图像的边缘接触矩形而不是所有外部部分,这意味着如果你有一艘船,例如,凹陷的边缘看起来很好,只有更宽的部分会有锯齿问题。我设法通过去photoshop解决这个问题,并将我的PNG文件缩放2个像素(取决于你的图像,也许你需要尝试不同的缩放因子),这样我仍然有相同的图像尺寸,但真实的图像(彩色像素)在旋转时不会触及图像的矩形。

于 2016-05-02T22:52:46.410 回答
0

不过,Rotozoom 似乎并没有平滑表面的边缘。也就是说,图像的内部看起来不错,但边缘仍然没有抗锯齿。

于 2015-11-25T13:49:11.307 回答