Python for 3dMax加载图像文件并读取像素值

使用Python for 3dMax加载和显示图像文件的示例:

*在这种情况下,EXR图像文件与3dMax文件位于同一目录中。

from MaxPlus import BitmapManager
image_file_path = r'BG_park_A.exr'
bmp_storage = MaxPlus.Factory.CreateStorage(17)
bmp_info = bmp_storage.GetBitmapInfo()
bmp_info.SetName(image_file_path)
bmp = BitmapManager.Load(bmp_info)
bmp.Display()

逐行编写解释脚本:

1.导入加载图像文件所需的BitmapManager类。

2.设置包含图像文件路径的变量

3.调用MaxPlus.Factory类的CreateStorage方法来初始化BitmapStorage对象。

这太尴尬了。。

很可能我只是没有找到正确的方法。。

除了启动BitmapStorage对象并引用其BitmapInfo对象外,我找不到任何其他方法来独立启动加载图像所需的BitmapInfo。(BitmapInfo类没有构造函数。)

*如果你知道更好的方法,如果你花时间发表评论,我将不胜感激。

注:

我们提供的17整数自变量将存储设置为与以下内容兼容:

32位浮点颜色深度格式(不带alpha通道)。

*他们编写了一个类,其中包含方便命名的整数参数常量(请参阅下面的示例代码)。

*在这个创建BitmapStorage作为生成BitmapInfo对象的方法的例子中,您提供的实际格式无关紧要,但您不能使用无法写入的格式,例如8(见下面的列表)

4.获取对BitmapStorage对象中包含的BitmapInfo对象的引用。

5.设置BitmapInfo对象的名称属性(完整文件路径)。

6.加载图像。

7.在3ds max的图像查看器窗口中显示图像。

BitmapStorage格式常量容器类的示例代码:

class BitmapTypes(object):
     BMM_NO_TYPE = 0 # Not allocated yet
     BMM_LINE_ART = 1 # 1-bit monochrome image
     BMM_PALETTED = 2 # 8-bit paletted image. Each pixel value is an index into the color table.
     BMM_GRAY_8 = 3 # 8-bit grayscale bitmap.
     BMM_GRAY_16 = 4 # 16-bit grayscale bitmap.
     BMM_TRUE_16 = 5 # 16-bit true color image.
     BMM_TRUE_32 = 6 # 32-bit color: 8 bits each for Red, Green, Blue, and Alpha.
     BMM_TRUE_64 = 7 # 64-bit color: 16 bits each for Red, Green, Blue, and Alpha.
     BMM_TRUE_24 = 8 # 24-bit color: 8 bits each for Red, Green, and Blue. Cannot be written to.
     BMM_TRUE_48 = 9 # 48-bit color: 16 bits each for Red, Green, and Blue. Cannot be written to.
     BMM_YUV_422 = 10 # This is the YUV format - CCIR 601. Cannot be written to.
     BMM_BMP_4 = 11 # Windows BMP 16-bit color bitmap. Cannot be written to.
     BMM_PAD_24 = 12 # Padded 24-bit (in a 32 bit register). Cannot be written to.
     BMM_LOGLUV_32 = 13 BMM_LOGLUV_24 = 14
     BMM_LOGLUV_24A = 15 BMM_REALPIX_32 = 16 # The 'Real Pixel' format.
     BMM_FLOAT_RGBA_32 = 17 # 32-bit floating-point per component (non-compressed),
     RGB with or without alpha
     BMM_FLOAT_GRAY_32 = 18 # 32-bit floating-point (non-compressed), monochrome/grayscale
     BMM_FLOAT_RGB_32 = 19
     BMM_FLOAT_A_32 = 20

从图像中读取像素值:

bmp_storage = bmp.GetStorage()
hdr_pixel = bmp_storage.GetHDRPixel(3000,200)
print(hdr_pixel)

1.获取对位图的BitmapStorage对象的引用。

*在这种情况下,重写我们之前创建的BitmapStorage对象只是为了获得BitmapInfo对象。。

2.读取像素值。

猜你喜欢

转载自blog.csdn.net/mufenglaoshi/article/details/132780452
今日推荐