Python代码:批量将BMP图片格式转换为JPG图片格式

谁都会走 提交于 2019-11-26 03:29:27

1. 介绍

Python代码:批量将BMP图片格式转换为JPG图片格式,即BMP转JPG格式。

2. Python代码

# 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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!