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()