Samsquanch
Samsquanch

Reputation: 9146

Getting pixel color at location with pygame

I'm drawing a bunch of rectangles to the siaply screen, and I'm wondering how I would go about reading the rgb color at a certain pixel location? For example, I want to get the color of the pixel at location 0,0 on the display screen, and it return the value [0,0,0] (or similar).

Upvotes: 16

Views: 30931

Answers (1)

FogleBird
FogleBird

Reputation: 76772

http://www.pygame.org/docs/ref/surface.html#Surface.get_at

Surface.get_at((x, y)): return Color

Return a copy of the RGBA Color value at the given pixel. If the Surface has no per pixel alpha, then the alpha value will always be 255 (opaque). If the pixel position is outside the area of the Surface an IndexError exception will be raised.

Upvotes: 19

Related Questions