문제

I would like to rotate an image and also keep the edges smooth.

This is how it looks like

original image

And after rotating

rotated image

The code I'm using looks like

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

Is there something I'm doing wrong?

도움이 되었습니까?

해결책

Try using pygame.transform.rotozoom with a scale of 1. It says it's filtered, I think that means AA.

다른 팁

The problem with rotozoom is where the image's edges touch the rectangle and not all the outer parts, that means if you have a ship ,for instance, the recessed edges will look fine only the wider parts will have the aliasing problem. I managed to fix that by going to photoshop and scale in my PNG file by 2 pixels(depends on your image maybe you'll need to experiment with different scaling factors), this way i still have the same image's dimensions but the real image(the colored pixels) will not touch the image's rectangle while rotating.

Rotozoom doesn't seem to smooth the edges of a surface, though. That is, the inner part of the image will look nice, but the edge is still non-antialiased.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top