南京学做网站,北龙中网 可信网站验证 费用,网页搜索的快捷键,郑州市建网站如何使用Python在3dmax中加载和显示图像文件#xff1f;我们先看下面的代码#xff1a;
*测试的3dmax文件和图像文件位于同一目录中。
from MaxPlus import BitmapManagerimage_file_path rje_gray_02_4k.exrbmp_storage MaxPlus.Factory.CreateStorage(17)bmp_info bmp…如何使用Python在3dmax中加载和显示图像文件我们先看下面的代码
*测试的3dmax文件和图像文件位于同一目录中。
from MaxPlus import BitmapManagerimage_file_path rje_gray_02_4k.exrbmp_storage MaxPlus.Factory.CreateStorage(17)bmp_info bmp_storage.GetBitmapInfo()bmp_info.SetName(image_file_path)bmp BitmapManager.Load(bmp_info)bmp.Display()
打开3dmax点击3dmax主菜单-脚本-新建脚本将上面的Python代码复制粘贴到MAXScript脚本编辑器窗口中点击脚本编辑器窗口上面的“语言”菜单选择“Python”。然后同时按下“Ctrle”键执行Python脚本运行结果如下图 下面一步一步解释上面的脚本
1.导入加载图像文件所需的BitmapManager类。
2.设置包含图像文件路径的变量
3.呼叫MaxPlus。Factory类的CreateStorage方法来启动BitmapStorage对象。
这太尴尬了。。
很可能我只是没有找到正确的方法。。
除了启动BitmapStorage对象并引用其BitmapInfo对象外貌似找不到任何其他方法来独立启动加载图像所需的BitmapInfo。BitmapInfo类没有构造函数。
4.获取对BitmapStorage对象中包含的BitmapInfo对象的引用。
5.设置BitmapInfo对象的名称属性完整文件路径。
6.加载图像。
7.在3dmax的图像查看器窗口中显示图像。 下面是BitmapStorage格式常量容器类的示例代码
class BitmapTypes(object):BMM_NO_TYPE 0 # Not allocated yetBMM_LINE_ART 1 # 1-bit monochrome imageBMM_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 14BMM_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 alphaBMM_FLOAT_GRAY_32 18 # 32-bit floating-point (non-compressed), monochrome/grayscaleBMM_FLOAT_RGB_32 19BMM_FLOAT_A_32 20
如何从图像中读取像素值看下面的Python代码
bmp_storage bmp.GetStorage()hdr_pixel bmp_storage.GetHDRPixel(3000,200)print(hdr_pixel)
将这段代码追加到之前代码的末尾完整代码如下
from MaxPlus import BitmapManagerimage_file_path rje_gray_02_4k.exrbmp_storage MaxPlus.Factory.CreateStorage(17)bmp_info bmp_storage.GetBitmapInfo()bmp_info.SetName(image_file_path)bmp BitmapManager.Load(bmp_info)bmp.Display()#reading pixelsbmp_storage bmp.GetStorage()hdr_pixel bmp_storage.GetHDRPixel(3000,200)print(hdr_pixel)
执行Python代码结果如下 代码释义
1.获取对位图的BitmapStorage对象的引用。
*在这种情况下重写我们之前创建的BitmapStorage对象只是为了获得BitmapInfo对象。。
2.读取像素值。 提示复制和粘贴此示例中的脚本时请注意格式的缩进。