From dee4125942158d8313ed1b1e5bd1d4e021257a80 Mon Sep 17 00:00:00 2001 From: Luthics Date: Sat, 7 Jan 2023 00:16:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index acfc3bc..c162b37 100644 --- a/main.py +++ b/main.py @@ -28,8 +28,8 @@ new_height = int(input("请输入新高度(px):")) # new_height = 128 # 读入图片 -imgFile = open(img, 'rb') -imgBytes = imgFile.read() +with open(img, 'rb') as f: + imgBytes = f.read() # 文件头处理 # 检验文件头是否为 BM @@ -170,7 +170,4 @@ for i in range(len(newpixels)): newimgBytes = bytes(newimgArray) with open(img[:-4] + "_new" + img[-4:], 'wb') as f: - f.write(newimgBytes) - -# 关闭文件 -imgFile.close() \ No newline at end of file + f.write(newimgBytes) \ No newline at end of file