24 lines
845 B
Python
24 lines
845 B
Python
import os
|
|
from PIL import Image
|
|
|
|
# 输入目录和输出目录
|
|
input_directory = 'E:/Jfen_work/DWIN/GUI_PUMP_ICL/132-mode'
|
|
output_directory = 'E:/Jfen_work/DWIN/GUI_PUMP_ICL/132-mode-new'
|
|
|
|
# 确保输出目录存在
|
|
if not os.path.exists(output_directory):
|
|
os.makedirs(output_directory)
|
|
|
|
# 遍历输入目录中的所有文件
|
|
for filename in os.listdir(input_directory):
|
|
if filename.endswith('.bmp'):
|
|
# 打开 .bmp 文件
|
|
bmp_image_path = os.path.join(input_directory, filename)
|
|
with Image.open(bmp_image_path) as img:
|
|
# 创建 .jpg 文件路径
|
|
jpg_image_path = os.path.join(output_directory, os.path.splitext(filename)[0] + '.jpg')
|
|
# 将图片转换为 RGB 模式并保存为 .jpg 文件
|
|
img.convert('RGB').save(jpg_image_path, 'JPEG')
|
|
|
|
print("转换完成!")
|