Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.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 如何为像素指定一个值,然后获取该值';s坐标_Python_Random_Pixels_Getpixel - Fatal编程技术网

Python 如何为像素指定一个值,然后获取该值';s坐标

Python 如何为像素指定一个值,然后获取该值';s坐标,python,random,pixels,getpixel,Python,Random,Pixels,Getpixel,我刚拿到IT学位几周,我正试图用Python编写一个小程序,我试图寻找一个解决方案,但我对术语和概念的了解可能会限制我的结果。也就是说,我试图找出是否有可能在一个随机范围内给一个像素赋值,然后得到该值的x,y并对其进行操作。比如说 import random pic=makeEmptyPicture(500,500) w=random.randint(0,getWidth(pic)) h=random.randint(0,getHeight(pic)) a=getPixel(pic,w,h) f

我刚拿到IT学位几周,我正试图用Python编写一个小程序,我试图寻找一个解决方案,但我对术语和概念的了解可能会限制我的结果。也就是说,我试图找出是否有可能在一个随机范围内给一个像素赋值,然后得到该值的x,y并对其进行操作。比如说

import random
pic=makeEmptyPicture(500,500)
w=random.randint(0,getWidth(pic))
h=random.randint(0,getHeight(pic))
a=getPixel(pic,w,h)
for x in range(getX(a),getX(a+5),1): #this is where I'm stuck.
    for y in range(getY(a),getY(a+5),1): #I need to get the x,y of "a"
        #Do something                    #and manipulate it.

提前感谢。

变量
w
h
是(x,y)坐标

要操纵那个像素,我需要了解你的“图片”对象

首先,查看
makeEmptyPicture
返回的对象类型。然后看看这个对象,看看它是否有任何有用的功能

pic = makeEmptyPicture(500, 500)
print("type: ", type(pic))
for var in dir(pic):
    print(var)
如果这还不够,请使用Python内置的“help”命令


这些可能会给你一些好的线索。如果您仍然卡住,请发布结果,我会帮助您。

这没有意义-您检索到的像素坐标当然是
w
h
参数,您传递给
getPixel()
。我试图使用w,h生成第二个随机坐标,以便稍后在程序中使用另一个值。我应该提供更多的信息对不起。我在这一节中发现了错误。我需要从括号中取出+5。谢谢你的意见。
pic = makeEmptyPicture(500, 500)
help(pic)