使用 .zoom 或 .subsample 调整 PhotoImage 的大小

Resize PhotoImage using .zoom or .subsample

我想在加载阶段调整 PhotoImage 的大小。如您所知,.zoom.subsample 不能使用浮点变量,只能使用整数。现在我用错误的方式调整它的大小:

i1=PhotoImage(file="res\1h.gif").zoom(new_size).subsample(old_size)

它适用于小图片,但现在我尝试使用中图片,但出现错误:

self.tk.call(destImage, 'copy', self.name, '-zoom',x,y)

_tkinter.TclError: not enough free memory for image buffer

嘿嘿,如果你想调整 PhotoImage 的大小,你可以使用 2 种方法:

  • .zoom(number) : return 大图 >> {number} 倍大
  • 或 .subsample(number) :return 较小的图像 >> 小 {number} 倍