【问题标题】:How can I convert a .dds file to a .png in python?如何在 python 中将 .dds 文件转换为 .png?
【发布时间】:2018-04-07 06:43:03
【问题描述】:

我正在尝试通过处理存储在 .dds 文件中的图像片段来创建一些图像,然后将完成的图像写入 .png。我看到 Direct Python 11 中有一个 dds python 模块,除了保存为 .dds 格式之外,这似乎就足够了。有没有办法保存为另一种图像格式?

【问题讨论】:

    标签: python image dds-format


    【解决方案1】:

    由于Python Imaging Library 链接不可用,我将展示wand 库的实际解决方案:

    from wand import image
    with image.Image(filename="white_rect_dxt3.dds") as img:
        img.compression = "no"
        img.save(filename="white_rect_dxt3.png")
    

    .png.dds 也是如此

    from wand import image
    with image.Image(filename='white_rect.png') as img:
        img.compression = "dxt3"
        img.save(filename='white_rect_dxt3.dds')
    

    【讨论】:

    • 无法让它与 Pillow 一起使用,但魔杖的作用就像一个魅力!
    【解决方案2】:

    Python Imaging Library 有一个open() 方法,支持dds 文件并具有读取功能,save() 可以将图像保存为多种格式(包括png)。

    请注意,目前仅支持 DXT1、DXT3 和 DXT5 像素格式,并且仅支持 RGBA 模式。

    【讨论】:

      猜你喜欢
      • 2018-03-05
      • 2020-04-29
      • 2016-10-31
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 2020-01-05
      相关资源
      最近更新 更多