使用 pygame 在位置获取像素颜色 [英] Getting pixel color at location with pygame
问题描述
我正在 siaply 屏幕上绘制一堆矩形,我想知道如何在某个像素位置读取 rgb 颜色?例如,我想获取显示屏上位置 0,0 处像素的颜色,并返回值 [0,0,0](或类似值).
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).
推荐答案
http://www.pygame.org/docs/ref/surface.html#Surface.get_at
Surface.get_at((x, y)):返回颜色
返回 RGBA 颜色的副本给定像素的值.如果 Surface 没有每像素 alpha,则alpha 值将始终为 255(不透明).如果像素位置是在 Surface 区域之外,一个 IndexError 异常将是提升.
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.
这篇关于使用 pygame 在位置获取像素颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!