怎么在python中将bmp转换为jpg

这期内容当中小编将会给大家带来有关怎么在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()

python是什么意思

Python是一种跨平台的、具有解释性、编译性、互动性和面向对象的脚本语言,其最初的设计是用于编写自动化脚本,随着版本的不断更新和新功能的添加,常用于用于开发独立的项目和大型项目。

上述就是小编为大家分享的怎么在python中将bmp转换为jpg了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。