我正在开展一个项目,我需要多次打印用户选择的任何图像。
我的代码大部分都在工作,但我需要制作一个嵌套循环,它基本上会改变原始图像的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.
答案 0 :(得分:0)
您正在newY = ypos + h * val
进行newY = ypos + h * loop
。
此外,您在val上的循环应停在loop < val
而不是loop <= val
。最后一个副本是不需要的(它是(val + 1)th),这是让你认为程序失败的部分。