如何在vtkplotlib的QtFigure组件中设置背景透明度为0
vtkplotlib QtFigure2 背景透明度设置解决方案
vtkplotlib 的 background_color 属性原生支持RGBA四通道参数,第四个参数即为透明度通道,取值范围0-255,设为0时即为完全透明,你可以直接修改背景色赋值语句实现需求。
修改后的示例代码如下:
import vtkplotlib as vpl # ModelViewer ModelViewer = vpl.QtFigure2(name="Model viewer") ModelViewer.add_screenshot_button(pixels=1080) ModelViewer.add_preset_views() ModelViewer.add_cursor_tracker() # 设置完全透明背景,四通道格式为[R, G, B, 透明度],透明度0为完全透明 ModelViewer.background_color = [255, 255, 255, 0] # add model plot = vpl.mesh_plot(vpl.data.get_rabbit_stl(), color=[0,100,0], fig=ModelViewer, opacity=0.1) plot.name = "rabbit" ModelViewer.show()
补充注意事项:
- 若需要导出截图时保留透明背景,调用截图方法时需额外传入
transparent_background=True参数,示例:ModelViewer.screenshot("output.png", transparent_background=True) - 透明度取值范围和RGB通道一致,数值越低透明度越高,255为完全不透明
内容的提问来源于stack exchange,提问作者marxcell
相关产品推荐
相关产品推荐

