0
我有一些代码使用Pillow的作物方法将单个图像分割成多个子图像。我的代码是类似以下内容:在枕头中重复使用裁剪方法的问题(Python的PIL叉)
from PIL import Image
from PIL import ImageTk
import Tkinter
# Open image from file path
baseimg = Image.open("PathToLargeImage.tif")
# Get image attributes
height = baseimg.height
width = baseimg.width
# Create a list of sub-images
subimages = []
for y in range(0, height, 50):
subimage = baseimg.crop((0, y, width, 10))
subimage.load() # Call load on sub-image to detach it from baseimg
subimages.append(subimage)
showimage(subimage)
当我拨打电话,显示子图像第一子图像将正常显示,那么所有下面的子图像将具有零高度(从调试发现与PyCharm)和显示不正确。
的showimage功能使用Tkinter的是如下:
def showimage(img):
# Build main window
root = Tkinter.Tk()
# Convert image
tkimage = ImageTk.PhotoImage(img)
# Add image on window
Tkinter.Label(root, image=tkimage).pack()
# Start gui loop
root.mainloop()