【问题标题】:how to convert a numpy array into a wand.image.Image object?如何将 numpy 数组转换为 wand.image.Image 对象?
【发布时间】:2021-07-06 16:19:09
【问题描述】:

我想将一个 numpy 数组保存为 .dds 文件,这是我获得数组的方式:

import numpy as np
from wand import image

with image.Image(filename='test.dds') as dds:
    arr = np.array(dds)

获得数组后,我需要使用以下代码将其另存为另一个 .dds 文件:

dds.compression = 'dxt5'
dds.save(filename='test2.dds')

但似乎 dds 必须是 wand.image.Image 对象,所以我的问题是,如何将 numpy 数组转换为 wand.image.Image 对象?

【问题讨论】:

    标签: python numpy wand


    【解决方案1】:

    我想你想要类方法Image.from_array

    from wand.image import Image
    
    # Make wand Image from Numpy array
    wi = Image.from_array(numpyArray)
    

    【讨论】:

      【解决方案2】:

      您正在寻找wand.image.Image.from_array:

      ndds = dds.from_array(arr)
      ndds.compression = 'dxt5'
      ndds.save('test2.dds')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多