我尝试裁剪图片,从逻辑上讲是正确的,但是当我尝试加载图片时,它显示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)