VTK提供vtkTextActor类,用于显示和使用二维文字。可通过 GetTextProperty()方法为文字设置字体、大小、颜色等属性。SetInput()方法设置显示内容。以下C#代码为新建一个 vtkTextActor对象,并在renderer中调用和实现。
vtkTextActor textActor = new vtkTextActor();
textActor.GetTextProperty().SetFontSize(30); // 文字大小
textActor.SetDisplayPosition(50, 50); // 文字位置(左下角)
textActor.SetInput("ActiViz, C# VTK"); // 文字内容
textActor.GetTextProperty().SetColor(1.0, 0.0, 0.0); // 文字颜色
//textActor.GetTextProperty().SetFontFamily(0); // 字体
//textActor.GetTextProperty().SetJustification(1); // 两端对其
//textActor.GetTextProperty().SetBold(1); // 加粗
//textActor.GetTextProperty().SetItalic(1); // 斜体
//textActor.GetTextProperty().SetShadow(1); // 阴影
render1.AddActor(textActor); // 在renderer中调用
程序运行效果如下:
C#完整的render控件载入部分源代码如下: