python - Pygame 中的分割图像

标签 python image split pygame blit

我在 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/

相关文章:

python - Python 子进程中的特殊字符问题

python - 使用连续高于 x 的列值将 pandas df 分成组

html - 无法删除图像上的边框 - css

python : Splitting multidimensional lists

java - 将一个文件剪切成多个文件(Java)

python - 了解 Python 中的嵌套列表

html - 向 .img-circle Bootstrap 元素添加悬停功能

c# - 调整许多位图大小时出现内存不足异常

r - 计算向量中连续对的数量

python - 使用python保存CSV文件