我是靠谱客的博主 现代石头,这篇文章主要介绍python bmp转jpg,现在分享给大家,希望可以做个参考。

import os
from PIL import Image

classes={'藏','川','鄂','甘','赣','贵','桂','黑','沪','吉','冀','津','晋','京','辽','鲁','蒙','闽','宁','青','琼',
'陕','苏','皖','湘','新','渝','豫','粤','云','浙'}
def bmpToJpg(file_path):
   for fileName in os.listdir(file_path):
       print(fileName)
       newFileName = fileName[0:fileName.find(".bmp")]+".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 = "F:\pycharm\charSamples\train\training-set\"
   for index,name in enumerate(classes):
       path=file_path+name
       bmpToJpg(path)
       deleteImages(path, "bmp")


if __name__ == '__main__':
   main()

最后

以上就是现代石头最近收集整理的关于python bmp转jpg的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部