Cannot zoom tkinter PhotoImage: _tkinter.TclError: not enough free memory for image buffer

Cannot zoom tkinter PhotoImage: _tkinter.TclError: not enough free memory for image buffer

我有一个 canvas,宽度为 w,高度为 h。我正在尝试使用 image = image.zoom(w).subsample(800) 将我的 (1000 x 800) 图像放在上面。但它给了我错误:_tkinter.TclError: not enough free memory for image buffer。有人可以帮忙吗?

当您调用 zoom 时,第一个参数指定每个像素 多少。如果您只提供 x 值,则 y 值将与 x 值相同。因此,如果 w 为 1000,zoom(x) 将尝试创建一个 100 万像素宽 x 800,000 像素高的图像。这几乎是 1 TB 的图像数据。