Update image_sharp.py

main
pos97em56 5 months ago
parent 87a6541480
commit 6c1bb98f70

@ -45,45 +45,6 @@ def select_image(root):
else: else:
messagebox.showerror("错误", "没有选择图片路径") messagebox.showerror("错误", "没有选择图片路径")
def select_image(root):
global img_path, src, img_label
img_path = filedialog.askopenfilename(filetypes=[("Image files", "*.jpg;*.png;*.jpeg;*.bmp")])
if img_path:
# 确保路径中的反斜杠正确处理,并使用 UTF-8 编码处理中文路径
img_path_fixed = os.path.normpath(img_path)
# 图像输入
src_temp = cv2.imdecode(np.fromfile(img_path_fixed, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
if src_temp is None:
messagebox.showerror("错误", "无法读取图片,请选择有效的图片路径")
return
src = cv2.cvtColor(src_temp, cv2.COLOR_BGR2RGB)
# 检查 img_label 是否存在且有效
if img_label is None or not img_label.winfo_exists():
img_label = tk.Label(root)
img_label.pack(side=tk.TOP, pady=10)
img = Image.open(img_path)
img.thumbnail((160, 160))
img_tk = ImageTk.PhotoImage(img)
img_label.configure(image=img_tk)
img_label.image = img_tk
src = cv2.cvtColor(src, cv2.COLOR_BGR2RGB)
else:
messagebox.showerror("错误", "没有选择图片路径")
def show_selected_image(root):
global img_label
img_label = tk.Label(root)
img_label.pack(side=tk.TOP, pady=10)
img = Image.open(img_path)
img.thumbnail((200, 200))
img_tk = ImageTk.PhotoImage(img)
img_label.configure(image=img_tk)
img_label.image = img_tk
def changeSize(event, img, LabelPic): def changeSize(event, img, LabelPic):
img_aspect = img.shape[1] / img.shape[0] img_aspect = img.shape[1] / img.shape[0]
new_aspect = event.width / event.height new_aspect = event.width / event.height

Loading…
Cancel
Save