Проблемы при обрезке картинок - PullRequest
0 голосов
/ 03 мая 2019

Я пытался обрезать картинки, и логически это правильно, но когда я пытался загрузить его, он показывает, что getPixel(picture,x,y): x (= 155) меньше 0 или больше ширины (= 154). И я не знаю, почему

def newPic(file):
 pic = makePicture(file)
 width = getWidth(pic)
 height = getHeight(pic)
 if width>height:
   newpic = makeEmptyPicture(height,height)
 if width<height:
   newpic = makeEmptyPicture(width,width)
 if width>height:
 min = height
 for x in range((width-height)/2,width-(width-height)/2-1):
  for y in range(0,height-1):
   pixel = getPixel(pic,x,y)
   pixelColor = getColor(pixel)
   newpixel = getPixel(newpic,x,y)
   setColor(newpixel,pixelColor)
 if width<=height:
  min = width
  for x in range(0,width-1):
  for y in range((height-width)/2,height-(height-width)/2-1):
  pixel = getPixel(pic,x,y)
  pixelColor = getColor(pixel)
  newpixel = getPixel(newpic,x,y)
  setColor(newpixel,pixelColor)
 repaint(newpic)
...