简体   繁体   中英

Inappropriate argument value (of correct type). An error occurred attempting to pass an argument to a function

For A class that I am taking I need to create a Collage using three images. Whenever I try and run the program I get an error. "Inappropriate argument value (of the correct type). An error occurred attempting to pass an argument to a function. Please check line 26" I am confused as to what the issue is I have it written exactly the same for another image above this. But it dose not cause an error on that line. Any help would be greatly appreciated.

 def createCollage():
  fileName1 = pickAFile()
  src1= makePicture(fileName1)
  print(src1)
  filename2= pickAFile()
  src2=makePicture(filename2)
  print(src2)
  filename3=pickAFile()
  src3=makePicture(filename3)
  print (src3)
  canvas=makeEmptyPicture(1300,1000)
  print canvas
  targetX=0
  for sourceX in range(0,getWidth(src3)):
    targetY=100
    for sourceY in range(0,getHeight(src3)):
      color=getColor(getPixel(src3,sourceX,sourceY))
      setColor(getPixel(canvas,targetX,targetY), color)
      targetY=targetY+1
    targetX=targetX+1
  targetX=650
  for sourceX in range(0,getWidth(src1)-100):
    targetY= 300
    for sourceY in range(0,getHeight(src1)-50):
      color=getColor(getPixel(src1,sourceX,sourceY))
      setColor(getPixel(canvas,targetX,targetY), color)
      targetY=targetY+1
    targetX=targetX+1
  targetX=600
  for sourceX in range(0,getWidth(src2)):
    targetY=430
    for sourceY in range(150,getHeight(src2)):
      color=getColor(getPixel(src2,sourceX,sourceY))
      setColor(getPixel(canvas,targetX,targetY), color)
      targetY=targetY+1
    targetX=targetX+1
  targetX=10
  for sourceX in range(20,getWidth(src2)-100):
    targetY=270
    for sourceY in range(0,getHeight(src2)-50):
      color=getColor(getPixel(src2,sourceX,sourceY))
      setColor(getPixel(canvas,targetX,targetY), color)
      targetY=targetY+1
    targetX=targetX+1
  targetX=50
  for sourceX in range(0,getWidth(src1)):
    targetY= 430
    for sourceY in range(120,getHeight(src1)):
      color=getColor(getPixel(src1,sourceX,sourceY))
      setColor(getPixel(canvas,targetX,targetY), color)
      targetY=targetY+1
    targetX=targetX+1
  show(src1)
  show(src2)
  show(src3)
  show(canvas)
  return canvas
  writePictureTo(canvas,("C:/Temp Python/CollagePic.png"))  
createCollage()

Your targetX value is out of bounds. The canvas image is 1300 pixels wide, but when you get the error, you're passing in x=1300 , which doesn't work with zero indexing. The range of valid pixel x-coordinates is 0-1299.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM