小bug修改

This commit is contained in:
Ray
2025-11-01 16:32:07 +08:00
parent 069613fe09
commit 4a0549114f
2 changed files with 6 additions and 2 deletions

View File

@@ -283,6 +283,7 @@ class PreviewWindow:
photo = ImageTk.PhotoImage(image=pil_image)
# 保持引用避免被GC
self.photo_objects[idx] = photo
self._grid_photos.append(photo)
images_to_draw.append((photo, center_x, center_y))
texts_to_draw.append((center_x, y + 15, name, 'white'))
@@ -416,6 +417,8 @@ class PreviewWindow:
canvas.pack(fill=tk.BOTH, expand=True)
photo_obj = {}
# 持久引用大窗当前帧 PhotoImage避免GC
self._large_photos = []
def update_large_once():
if not self.running or not self.large_window.winfo_exists():
@@ -441,8 +444,9 @@ class PreviewWindow:
resized_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
pil_image = Image.fromarray(resized_frame)
photo = ImageTk.PhotoImage(image=pil_image)
# 保存引用到字典确保不被GC
# 保存引用到字典和列表确保不被GC
photo_obj['img'] = photo
self._large_photos = [photo]
# 清空并绘制新图像
canvas.delete("all")