我在一个项目中工作,我需要打印用户选择的任何图像也由用户选择的次数。
我的代码大部分正常工作,但我需要创建一个嵌套循环,该循环将基本上更改原始图像的Xpos和Ypos的值,并将其更改为生成新图片。
def repeat(pic):
val = requestIntegerInRange("Enter 1-10", 1, 10)
print "The user entered :" + str(val)
w = getWidth(pic)
h = getHeight(pic)
print "Height and Width of this image are:", h, w
result = makeEmptyPicture(w, h * val)
xpos = 0
while(xpos < w):
ypos = 0
while(ypos < h):
pixel = getPixel(pic, xpos, ypos)
color = getColor(pixel)
loop = 0
while(loop <= val):
newX = xpos
newY = ypos + h * val
pixel2 = getPixel(result, newX, newY)
setColor(pixel2, color)
loop = loop + 1
ypos = ypos + 1
xpos = xpos + 1 这里,val是用户选择用于多次打印图像的值。
当我使用上面的代码运行我的程序时,它显示
The error value is:
Inappropriate argument value (of correct type).Height and Width of the Picture are : 208 146
getPixel(picture,x,y): y (= 1456) is less than 0 or bigger than the height (= 1455)
An error occurred attempting to pass an argument to a function.发布于 2018-03-22 23:40:33
你在应该是newY = ypos + h * loop的地方做newY = ypos + h * val。
此外,您在val上的循环应该在loop < val上停止,而不是在loop <= val上。最后一个拷贝是不需要的(第(val +1)次),我认为这就是让你的程序失败的部分。
https://stackoverflow.com/questions/49393827
复制相似问题