网络编程
位置:首页>> 网络编程>> Python编程>> python bmp转换为jpg 并删除原图的方法

python bmp转换为jpg 并删除原图的方法

作者:sunfellow2009  发布时间:2023-03-12 02:48:50 

标签:python,bmp,jpg

如下所示:


# coding:utf-8
import os

from PIL import Image

# bmp 转换为jpg
def bmpToJpg(file_path):
for fileName in os.listdir(file_path):
 # print(fileName)
 newFileName = fileName[0:fileName.find("_")]+".jpg"
 print(newFileName)
 im = Image.open(file_path+"\\"+fileName)
 im.save(file_path+"\\"+newFileName)

# 删除原来的位图
def deleteImages(file_path, imageFormat):
command = "del "+file_path+"\\*."+imageFormat
os.system(command)

def main():
file_path = "D:\\VideoPhotos"
bmpToJpg(file_path)
deleteImages(file_path, "bmp")

if __name__ == '__main__':
main()

来源:https://blog.csdn.net/sunfellow2009/article/details/80742599

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com