【问题标题】:how to get the color value of a pixel in pygame?如何在pygame中获取像素的颜色值?
【发布时间】:2019-01-16 17:47:15
【问题描述】:

我想获取一个像素的颜色值。我读过一些关于名为“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'

【问题讨论】:

标签: python pygame


【解决方案1】:

这里有两个问题:

  • get_at 需要一个元组 (x, y) 所以你应该调用它:

    .get_at((300, 200))
    
  • 您应该提供要为其获取像素颜色的表面。像这样的:

    screen = pygame.display.set_mode((150, 50))
    ...
    screen.get_at((300, 200))
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多