Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取窗口中指定像素的颜色_Python_Python 2.7_Pyglet - Fatal编程技术网

Python 获取窗口中指定像素的颜色

Python 获取窗口中指定像素的颜色,python,python-2.7,pyglet,Python,Python 2.7,Pyglet,我试图在pyglet上制作一个简单的程序,当用户点击图像时,它返回True,否则返回False。 我知道怎么做,但这是我的形象: 如您所见-此图像具有白色背景,我的pyglet窗口也具有白色背景,因此我现在要做的是,当用户单击的像素为除白色以外的任何颜色时,使其仅返回True。 我知道怎么做,但我需要知道的是如何检查某个像素的颜色 #This is getting and resizing the image kitty = pyglet.resource.image('kitty.jpg')

我试图在pyglet上制作一个简单的程序,当用户点击图像时,它返回
True
,否则返回
False
。 我知道怎么做,但这是我的形象:
如您所见-此图像具有白色背景,我的pyglet窗口也具有白色背景,因此我现在要做的是,当用户单击的像素为除白色以外的任何颜色时,使其仅返回
True

我知道怎么做,但我需要知道的是如何检查某个像素的颜色

#This is getting and resizing the image
kitty = pyglet.resource.image('kitty.jpg')
kitty.width = kitty.width//4
kitty.height = kitty.height//4

#These are variables of the coordinates
#to draw the image at
kitty_draw_x = 0
kitty_draw_y = 0

#And this is the function to draw the kitty!
@window.event
def on_draw():
    window.clear()
    kitty.blit(kitty_draw_x, kitty_draw_y)

您可以使用以下方式访问图像的像素:

rawimage = kitty .get_image_data()
format = 'RGBA'
pitch = rawimage.width * len(format)
pixels = rawimage.get_data(format, pitch)
然后使用以下方法获取像素x,y:

pixels[kitty.width * y + x]

你能写一些代码吗:如何显示图像?@lilezek好的,我已经添加了代码。