简体   繁体   English

如何在pygame中获取像素的颜色值?

[英]how to get the color value of a pixel in pygame?

I want to get the color value of a pixel. 我想获取像素的颜色值。 I have read something about a function called "pygame.Surface.get_at()". 我已经阅读了有关一个名为“ pygame.Surface.get_at()”的函数的内容。 But when I use this function i get this error: 但是,当我使用此功能时,出现此错误:

Traceback (most recent call last):
pygame.Surface.get_at(300, 200)
TypeError: descriptor 'get_at' requires a 'pygame.Surface' object but received a 'int'

You have two problems here: 您在这里有两个问题:

  • get_at requires a tuple (x, y) so you should invoke it with: get_at需要一个元组(x, y)因此应使用以下命令调用它:

     .get_at((300, 200)) 
  • You should provide the surface for which you want to get the pixel color. 您应该提供要获得其像素颜色的表面。 Something like this: 像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM