栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python图像格式转换 .png文件转换为.bmp

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python图像格式转换 .png文件转换为.bmp

if __name__ == '__main__':
    rootDir = r'G:PYwenjianvenvfenkuaitu11'
    imgStorePath = rootDir + '_BMP/'  # 存储路径
    if (not os.path.exists(imgStorePath)):
        os.makedirs(imgStorePath) #创建目录
    a_list = fnmatch.filter(os.listdir(rootDir),'*.png')
    for i in range(len(a_list)):
        path = rootDir+'/'+a_list[i]
        # 开始读取
        img = cv2.imdecode(np.fromfile(path, dtype=np.uint8), -1)
        # 直接调用.tofile(_path),我这里显示权限拒绝,所用系统自带的文件写入
        img_encode = cv2.imencode('.bmp',img)[1]

        # img = cv2.imread(path)

        t = a_list[i]
        t = t[:-4]  # 拿到图片名
        with open(imgStorePath + t + '.bmp', 'wb') as f: #写入
            f.write(img_encode)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/498806.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号