如何获取pygame中某个像素的颜色值?
how to get the color value of a pixel in pygame?
我想获取一个像素的颜色值。我已经阅读了一些关于名为 "pygame.Surface.get_at()" 的函数的内容。但是当我使用这个函数时,我得到了这个错误:
Traceback (most recent call last):
pygame.Surface.get_at(300, 200)
TypeError: descriptor 'get_at' requires a 'pygame.Surface' object but received a 'int'
你这里有两个问题:
get_at
需要一个元组 (x, y)
所以你应该调用它:
.get_at((300, 200))
您应该提供要获取其像素颜色的表面。像这样:
screen = pygame.display.set_mode((150, 50))
...
screen.get_at((300, 200))
我想获取一个像素的颜色值。我已经阅读了一些关于名为 "pygame.Surface.get_at()" 的函数的内容。但是当我使用这个函数时,我得到了这个错误:
Traceback (most recent call last):
pygame.Surface.get_at(300, 200)
TypeError: descriptor 'get_at' requires a 'pygame.Surface' object but received a 'int'
你这里有两个问题:
get_at
需要一个元组(x, y)
所以你应该调用它:.get_at((300, 200))
您应该提供要获取其像素颜色的表面。像这样:
screen = pygame.display.set_mode((150, 50)) ... screen.get_at((300, 200))