【发布时间】:2020-12-19 07:48:46
【问题描述】:
我正在尝试在此处裁剪图像,但是每次在裁剪后的图像上运行 .show() 时,都会出现错误。
使用 Python 3.9.1 和 Pillow 8.0
from PIL import Image
image = Image.open('image.PNG')
print (image.size)
width, height = image.size
print (width)
print (height)
newWidth = int(width/2)
newHeight = int(height/2)
print (newWidth)
print (newHeight)
img = image.crop((newWidth,newHeight,newWidth,newHeight))
img.show()
这就是错误的样子
【问题讨论】:
-
请复制错误代码并粘贴到这里,不要粘贴图片
-
crop()返回的图像可能不好,因为您传递给它的参数不正确。请参阅documentation。 box 参数应该是(left, upper, right, lower),这不是您要传递的内容——您定义了一个宽度和高度为零的矩形。
标签: python image python-imaging-library crop show