我只读了几个星期的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.提前谢谢。
发布于 2017-07-11 10:12:17
变量w和h是(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)这些可能会给你一些很好的线索。如果你仍然卡住了,把结果贴出来,我会帮你的。
https://stackoverflow.com/questions/45024171
复制相似问题