gpt4 book ai didi

python - Pygame 中的分割图像

转载 作者:行者123 更新时间:2023-11-28 21:27:15 27 4
gpt4 key购买 nike

我在 pygame 中有一张 200x200 像素的图像,我想将其切成两半,因此这 2 个形状将为 100x200 像素。之后,我想在屏幕上将 2 个新图像 blit,并在它们之间设置一定数量的像素。如何以这种方式分割/裁剪图像?

编辑 - 已修复!我设法通过使用 pygame.transform.chop()pygame.transform.rotate() 自己解决了这个问题。不过还是谢谢你的帮助。感谢 Tankor Smash 的帮助,我知道了更多。

最佳答案

你不需要创建两个图像,只需使用一个并 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)

关于python - Pygame 中的分割图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11420426/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com