如何为像素分配一个值,然后获取该值的坐标



我刚获得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.

提前谢谢。

变量wh是(x,y(坐标。

要操作该像素,我需要了解您的"图片"对象。

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

pic = makeEmptyPicture(500, 500)
print("type: ", type(pic))
for var in dir(pic):
print(var)

如果这些信息还不够,请使用 Python 内置的"help"命令。

pic = makeEmptyPicture(500, 500)
help(pic)

这些可能会给你一些很好的线索。如果您仍然遇到困难,请发布结果,我会帮助您。

相关内容

最新更新