在Pygame中拆分图像

Eri*_*ric 2 python split pygame image blit

我在pygame中有一个200x200px图像,我想切成两半,所以2个形状将是100x200px.之后,我想在屏幕上显示2个新图像,并在它们之间设置一定数量的像素.如何以这种方式分割/裁剪图像?

编辑 - 修复!我设法通过使用pygame.transform.chop()和自己来解决这个问题pygame.transform.rotate().谢谢你的帮助.感谢Tankor Smash的帮助,我知道了一点.

pmo*_*eri 5

您不需要创建两个图像,只需使用一个并将其blit两次:

origin1 = (0,0)
separation = 20

# Load the image
img = pygame.image.load(image_path)

width, height = img.get_width()/2, img.get_height()
origin2 = origin1[0] + width + separation, origin1[1]

# Blit first half
source_area = pygame.Rect((0,0), (width, height))
screen.blit(img, origin1, source_area)

# Blit second half
source_area = pygame.Rect((width,0), (width, height))
screen.blit(img, origin2, source_area)
Run Code Online (Sandbox Code Playgroud)